Skip to content

Commit

Permalink
update btrfs to 6.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Tsai committed Jun 11, 2024
1 parent d67a0d0 commit ed46e08
Show file tree
Hide file tree
Showing 71 changed files with 1,651 additions and 639 deletions.
2 changes: 1 addition & 1 deletion src/btrfs/check/qgroup-verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,9 +960,9 @@ static int load_quota_info(struct btrfs_fs_info *info)
* items. The 2nd pass picks up relation items and glues them to their
* respective count structures.
*/
key.offset = 0;
key.objectid = search_relations ? 0 : BTRFS_QGROUP_RELATION_KEY;
key.type = 0;
key.offset = 0;

ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/btrfs/check/repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ static int populate_used_from_extent_root(struct btrfs_root *root,
int slot;
int ret;

key.offset = 0;
key.objectid = 0;
key.type = BTRFS_EXTENT_ITEM_KEY;
key.offset = 0;
ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret < 0)
return ret;
Expand Down
19 changes: 10 additions & 9 deletions src/btrfs/common/device-scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
device_total_bytes = (device_total_bytes / sectorsize) * sectorsize;

device = calloc(1, sizeof(*device));
if (!device) {
ret = -ENOMEM;
goto out;
}
if (!device)
return -ENOMEM;

buf = calloc(1, sectorsize);
if (!buf) {
ret = -ENOMEM;
Expand Down Expand Up @@ -208,7 +207,11 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,

ret = sbwrite(fd, buf, BTRFS_SUPER_INFO_OFFSET);
/* Ensure super block was written to the device */
BUG_ON(ret != BTRFS_SUPER_INFO_SIZE);
if (ret != BTRFS_SUPER_INFO_SIZE) {
error_msg(ERROR_MSG_WRITE, "superblock when adding device: %m");
ret = -EIO;
goto out;
}
free(buf);
list_add(&device->dev_list, &fs_info->fs_devices->devices);
device->fs_devices = fs_info->fs_devices;
Expand Down Expand Up @@ -313,8 +316,7 @@ int is_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[])
return 0;
}

int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[],
int fd, DIR *dirstream)
int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[], int fd)
{
u8 hash = fsid[0];
int slot = hash % SEEN_FSID_HASH_SIZE;
Expand Down Expand Up @@ -342,7 +344,6 @@ int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[],
alloc->next = NULL;
memcpy(alloc->fsid, fsid, BTRFS_FSID_SIZE);
alloc->fd = fd;
alloc->dirstream = dirstream;

if (seen)
seen->next = alloc;
Expand All @@ -362,7 +363,7 @@ void free_seen_fsid(struct seen_fsid *seen_fsid_hash[])
seen = seen_fsid_hash[slot];
while (seen) {
next = seen->next;
close_file_or_dir(seen->fd, seen->dirstream);
close(seen->fd);
free(seen);
seen = next;
}
Expand Down
24 changes: 12 additions & 12 deletions src/btrfs/common/device-scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
#include "kernel-lib/bitops.h"
#include "kernel-shared/uapi/btrfs.h"

#define BTRFS_SCAN_MOUNTED (1ULL << 0)
#define BTRFS_SCAN_LBLKID (1ULL << 1)

#define BTRFS_UPDATE_KERNEL 1
enum {
BTRFS_SCAN_MOUNTED = (1ULL << 0),
BTRFS_SCAN_LBLKID = (1ULL << 1)
};

#define BTRFS_ARG_UNKNOWN 0
#define BTRFS_ARG_MNTPOINT 1
#define BTRFS_ARG_UUID 2
#define BTRFS_ARG_BLKDEV 3
#define BTRFS_ARG_REG 4
enum {
BTRFS_ARG_UNKNOWN,
BTRFS_ARG_MNTPOINT,
BTRFS_ARG_UUID,
BTRFS_ARG_BLKDEV,
BTRFS_ARG_REG,
};

#define SEEN_FSID_HASH_SIZE 256

Expand All @@ -41,7 +43,6 @@ struct btrfs_trans_handle;
struct seen_fsid {
u8 fsid[BTRFS_FSID_SIZE];
struct seen_fsid *next;
DIR *dirstream;
int fd;
};

Expand All @@ -56,8 +57,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
int super_offset);
int is_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[]);
int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[],
int fd, DIR *dirstream);
int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[], int fd);
void free_seen_fsid(struct seen_fsid *seen_fsid_hash[]);
int test_uuid_unique(const char *uuid_str);

Expand Down
34 changes: 17 additions & 17 deletions src/btrfs/common/device-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ int device_zero_blocks(int fd, off_t start, size_t len, bool direct)
return -ENOMEM;
memset(buf, 0, len);
written = btrfs_pwrite(fd, buf, len, start, direct);
if (written != len)
if (written != len) {
error_msg(ERROR_MSG_WRITE, "zeroing range from %llu: %m",
(unsigned long long)start);
ret = -EIO;
}
free(buf);
return ret;
}
Expand Down Expand Up @@ -340,14 +343,14 @@ static u64 device_get_partition_size_sysfs(const char *dev)
char path[PATH_MAX] = {};
char sysfs[PATH_MAX] = {};
char sizebuf[128] = {};
char *name = NULL;
const char *name = NULL;
int sysfd;
unsigned long long size = 0;

name = realpath(dev, path);
if (!name)
return 0;
name = basename(path);
name = path_basename(path);

ret = path_cat3_out(sysfs, "/sys/class/block", name, "size");
if (ret < 0)
Expand Down Expand Up @@ -437,29 +440,25 @@ int device_get_queue_param(const char *file, const char *param, char *buf, size_
*/
u64 device_get_zone_unusable(int fd, u64 flags)
{
char buf[64];
int sys_fd;
u64 unusable = DEVICE_ZONE_UNUSABLE_UNKNOWN;
int ret;
u64 unusable;

/* Don't report it for a regular fs */
sys_fd = sysfs_open_fsid_file(fd, "features/zoned");
if (sys_fd < 0)
ret = sysfs_open_fsid_file(fd, "features/zoned");
if (ret < 0)
return DEVICE_ZONE_UNUSABLE_UNKNOWN;
close(sys_fd);
sys_fd = -1;
close(ret);
ret = -1;

if ((flags & BTRFS_BLOCK_GROUP_DATA) == BTRFS_BLOCK_GROUP_DATA)
sys_fd = sysfs_open_fsid_file(fd, "allocation/data/bytes_zone_unusable");
ret = sysfs_read_fsid_file_u64(fd, "allocation/data/bytes_zone_unusable", &unusable);
else if ((flags & BTRFS_BLOCK_GROUP_METADATA) == BTRFS_BLOCK_GROUP_METADATA)
sys_fd = sysfs_open_fsid_file(fd, "allocation/metadata/bytes_zone_unusable");
ret = sysfs_read_fsid_file_u64(fd, "allocation/metadata/bytes_zone_unusable", &unusable);
else if ((flags & BTRFS_BLOCK_GROUP_SYSTEM) == BTRFS_BLOCK_GROUP_SYSTEM)
sys_fd = sysfs_open_fsid_file(fd, "allocation/system/bytes_zone_unusable");
ret = sysfs_read_fsid_file_u64(fd, "allocation/system/bytes_zone_unusable", &unusable);

if (sys_fd < 0)
if (ret < 0)
return DEVICE_ZONE_UNUSABLE_UNKNOWN;
sysfs_read_file(sys_fd, buf, sizeof(buf));
unusable = strtoull(buf, NULL, 10);
close(sys_fd);

return unusable;
}
Expand Down Expand Up @@ -504,6 +503,7 @@ u64 device_get_zone_size(int fd, const char *name)
/* /sys/fs/btrfs/FSID/devices/NAME/queue/chunk_sectors */
queue_fd = sysfs_open_fsid_file(fd, queue);
if (queue_fd < 0) {
queue_fd = -1;
ret = 0;
break;
}
Expand Down
10 changes: 6 additions & 4 deletions src/btrfs/common/device-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ struct stat;
/*
* Options for btrfs_prepare_device
*/
#define PREP_DEVICE_ZERO_END (1U << 0)
#define PREP_DEVICE_DISCARD (1U << 1)
#define PREP_DEVICE_VERBOSE (1U << 2)
#define PREP_DEVICE_ZONED (1U << 3)
enum {
PREP_DEVICE_ZERO_END = (1U << 0),
PREP_DEVICE_DISCARD = (1U << 1),
PREP_DEVICE_VERBOSE = (1U << 2),
PREP_DEVICE_ZONED = (1U << 3),
};

/* Placeholder to denote no results for the zone_unusable sysfs value */
#define DEVICE_ZONE_UNUSABLE_UNKNOWN ((u64)-1)
Expand Down
24 changes: 12 additions & 12 deletions src/btrfs/common/extent-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ struct cache_extent_search_range {
u64 size;
};

static int cache_tree_comp_range(struct rb_node *node, void *data)
static int cache_tree_comp_range(const struct rb_node *node, const void *data)
{
struct cache_extent *entry;
struct cache_extent_search_range *range;
const struct cache_extent *entry;
const struct cache_extent_search_range *range;

range = (struct cache_extent_search_range *)data;
range = (const struct cache_extent_search_range *)data;
entry = rb_entry(node, struct cache_extent, rb_node);

if (entry->start + entry->size <= range->start)
Expand All @@ -45,9 +45,9 @@ static int cache_tree_comp_range(struct rb_node *node, void *data)
return 0;
}

static int cache_tree_comp_nodes(struct rb_node *node1, struct rb_node *node2)
static int cache_tree_comp_nodes(const struct rb_node *node1, const struct rb_node *node2)
{
struct cache_extent *entry;
const struct cache_extent *entry;
struct cache_extent_search_range range;

entry = rb_entry(node2, struct cache_extent, rb_node);
Expand All @@ -57,10 +57,10 @@ static int cache_tree_comp_nodes(struct rb_node *node1, struct rb_node *node2)
return cache_tree_comp_range(node1, (void *)&range);
}

static int cache_tree_comp_range2(struct rb_node *node, void *data)
static int cache_tree_comp_range2(const struct rb_node *node, const void *data)
{
struct cache_extent *entry;
struct cache_extent_search_range *range;
const struct cache_extent *entry;
const struct cache_extent_search_range *range;

range = (struct cache_extent_search_range *)data;
entry = rb_entry(node, struct cache_extent, rb_node);
Expand All @@ -77,17 +77,17 @@ static int cache_tree_comp_range2(struct rb_node *node, void *data)
return 0;
}

static int cache_tree_comp_nodes2(struct rb_node *node1, struct rb_node *node2)
static int cache_tree_comp_nodes2(const struct rb_node *node1, const struct rb_node *node2)
{
struct cache_extent *entry;
const struct cache_extent *entry;
struct cache_extent_search_range range;

entry = rb_entry(node2, struct cache_extent, rb_node);
range.objectid = entry->objectid;
range.start = entry->start;
range.size = entry->size;

return cache_tree_comp_range2(node1, (void *)&range);
return cache_tree_comp_range2(node1, &range);
}

void cache_tree_init(struct cache_tree *tree)
Expand Down
5 changes: 4 additions & 1 deletion src/btrfs/common/filesystem-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ static int set_label_unmounted(const char *dev, const char *label)
return -1;

trans = btrfs_start_transaction(root, 1);
BUG_ON(IS_ERR(trans));
if (IS_ERR(trans)) {
error_msg(ERROR_MSG_START_TRANS, "set label");
return PTR_ERR(trans);
}
__strncpy_null(root->fs_info->super_copy->label, label, BTRFS_LABEL_SIZE - 1);

btrfs_commit_transaction(trans, root);
Expand Down
Loading

0 comments on commit ed46e08

Please sign in to comment.