These are the patches from the Fedora 18 btrfs-progs package. This is resubmitted to pickup the other two patches by Josef Bacik. One of them had to be refitted/rebased because of changes to mkfs.c but only the original Josef changes are included. I claim no authorship and am simply passing these on to the btrfs mailing list. There are only six patches. The btrfs-init-dev-list.patch and the two Bacik patches are new to 18. The others all date back to at least Fedora 15 in early 2011. These patches were applied on top of the 19 patches assembled by David Sterba. The valgrind patch needed to be change to remove a small part which had already been fixed by the "plug a memory leak reported by cppcheck" patch. Gene Czarcinski (5): Fedora 18 - btrfs-init-dev-list.patch Fedora 18 - build-fixes.patch Fedora 18 - fix-labels.patch Fedora 18 - modified valgrind.patch Btrfs-progs: detect if the disk we are formatting is a ssd Josef Bacik (1): Btrfs-progs: add btrfs device ready command Makefile | 2 +- btrfsck.c | 2 ++ cmds-device.c | 35 +++++++++++++++++++++++++ disk-io.c | 16 ++++++++---- extent-cache.c | 11 ++++++++ extent-cache.h | 1 + extent-tree.c | 10 ++++++++ ioctl.h | 2 ++ man/mkfs.btrfs.8.in | 5 +++- mkfs.c | 74 ++++++++++++++++++++++++++++++++++++++++++++--------- utils.c | 3 ++- volumes.c | 16 +++++++++++- volumes.h | 1 + 13 files changed, 157 insertions(+), 21 deletions(-) -- 1.8.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Signed-off-by: Gene Czarcinski <gene@czarc.net> --- utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils.c b/utils.c index 938f9a5..51b78d5 100644 --- a/utils.c +++ b/utils.c @@ -477,7 +477,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, u64 num_devs; int ret; - device = kmalloc(sizeof(*device), GFP_NOFS); + device = kzalloc(sizeof(*device), GFP_NOFS); if (!device) return -ENOMEM; buf = kmalloc(sectorsize, GFP_NOFS); @@ -503,6 +503,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, device->bytes_used = 0; device->total_ios = 0; device->dev_root = root->fs_info->dev_root; + INIT_LIST_HEAD(&device->dev_list); ret = btrfs_add_device(trans, root, device); BUG_ON(ret); -- 1.8.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Signed-off-by: Gene Czarcinski <gene@czarc.net> --- btrfsck.c | 2 ++ mkfs.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/btrfsck.c b/btrfsck.c index a851008..6274ff7 100644 --- a/btrfsck.c +++ b/btrfsck.c @@ -22,7 +22,9 @@ #include <stdlib.h> #include <unistd.h> #include <fcntl.h> +#include <sys/types.h> #include <sys/stat.h> +#include <unistd.h> #include <getopt.h> #include "kerncompat.h" #include "ctree.h" diff --git a/mkfs.c b/mkfs.c index fbf8319..d123d5f 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1206,7 +1206,7 @@ int main(int ac, char **av) u64 alloc_start = 0; u64 metadata_profile = 0; u64 data_profile = 0; - u32 leafsize = getpagesize(); + u32 leafsize = sysconf(_SC_PAGESIZE); u32 sectorsize = 4096; u32 nodesize = leafsize; u32 stripesize = 4096; @@ -1282,7 +1282,7 @@ int main(int ac, char **av) print_usage(); } } - sectorsize = max(sectorsize, (u32)getpagesize()); + sectorsize = max(sectorsize, (u32)sysconf(_SC_PAGESIZE)); if (check_leaf_or_node_size(leafsize, sectorsize)) exit(1); if (check_leaf_or_node_size(nodesize, sectorsize)) -- 1.8.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Signed-off-by: Gene Czarcinski <gene@czarc.net> --- mkfs.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/mkfs.c b/mkfs.c index d123d5f..8c291c9 100644 --- a/mkfs.c +++ b/mkfs.c @@ -352,7 +352,6 @@ static u64 parse_profile(char *s) static char *parse_label(char *input) { - int i; int len = strlen(input); if (len >= BTRFS_LABEL_SIZE) { @@ -360,12 +359,6 @@ static char *parse_label(char *input) BTRFS_LABEL_SIZE - 1); exit(1); } - for (i = 0; i < len; i++) { - if (input[i] == ''/'' || input[i] == ''\\'') { - fprintf(stderr, "invalid label %s\n", input); - exit(1); - } - } return strdup(input); } -- 1.8.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
A small part of this patch proved unnecessary because it was already corrected by the plug a memory leak reported by cppcheck patch. Signed-off-by: Gene Czarcinski <gene@czarc.net> --- disk-io.c | 16 +++++++++++----- extent-cache.c | 11 +++++++++++ extent-cache.h | 1 + extent-tree.c | 10 ++++++++++ volumes.c | 16 +++++++++++++++- volumes.h | 1 + 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/disk-io.c b/disk-io.c index c4d4631..5b6c6b1 100644 --- a/disk-io.c +++ b/disk-io.c @@ -631,7 +631,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, struct btrfs_root *chunk_root = malloc(sizeof(struct btrfs_root)); struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root)); struct btrfs_root *csum_root = malloc(sizeof(struct btrfs_root)); - struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info)); + struct btrfs_fs_info *fs_info = malloc(sizeof(struct btrfs_fs_info)); int ret; struct btrfs_super_block *disk_super; struct btrfs_fs_devices *fs_devices = NULL; @@ -655,7 +655,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, goto out; } - memset(fs_info, 0, sizeof(*fs_info)); + memset(fs_info, 0, sizeof(struct btrfs_fs_info)); fs_info->tree_root = tree_root; fs_info->extent_root = extent_root; fs_info->chunk_root = chunk_root; @@ -1084,15 +1084,19 @@ static int close_all_devices(struct btrfs_fs_info *fs_info) { struct list_head *list; struct list_head *next; + struct list_head *tmp; struct btrfs_device *device; - return 0; - list = &fs_info->fs_devices->devices; - list_for_each(next, list) { + list_for_each_safe(next, tmp, list) { device = list_entry(next, struct btrfs_device, dev_list); close(device->fd); + list_del(&device->dev_list); + free(device->name); + free(device->label); + free(device); } + free(fs_info->fs_devices); return 0; } @@ -1142,12 +1146,14 @@ int close_ctree(struct btrfs_root *root) extent_io_tree_cleanup(&fs_info->pinned_extents); extent_io_tree_cleanup(&fs_info->pending_del); extent_io_tree_cleanup(&fs_info->extent_ins); + btrfs_mapping_tree_free(&fs_info->mapping_tree); free(fs_info->tree_root); free(fs_info->extent_root); free(fs_info->chunk_root); free(fs_info->dev_root); free(fs_info->csum_root); + free(fs_info->log_root_tree); free(fs_info); return 0; diff --git a/extent-cache.c b/extent-cache.c index 3dd6434..84d4bbc 100644 --- a/extent-cache.c +++ b/extent-cache.c @@ -168,3 +168,14 @@ void remove_cache_extent(struct cache_tree *tree, rb_erase(&pe->rb_node, &tree->root); } +void free_cache_tree(struct cache_tree *tree) +{ + struct rb_node *node; + struct cache_extent *cache; + + while ((node = rb_last(&tree->root)) != NULL) { + cache = rb_entry(node, struct cache_extent, rb_node); + remove_cache_extent(tree, cache); + free(cache); + } +} diff --git a/extent-cache.h b/extent-cache.h index 7f2f2a6..1696bc2 100644 --- a/extent-cache.h +++ b/extent-cache.h @@ -43,6 +43,7 @@ struct cache_extent *find_cache_extent(struct cache_tree *tree, int insert_cache_extent(struct cache_tree *tree, u64 start, u64 size); int insert_existing_cache_extent(struct cache_tree *tree, struct cache_extent *pe); +void free_cache_tree(struct cache_tree *tree); static inline int cache_tree_empty(struct cache_tree *tree) { diff --git a/extent-tree.c b/extent-tree.c index 20cdffa..d644d9a 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -2999,6 +2999,7 @@ out: int btrfs_free_block_groups(struct btrfs_fs_info *info) { + struct btrfs_space_info *space_info; u64 start; u64 end; u64 ptr; @@ -3022,6 +3023,15 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) clear_extent_dirty(&info->free_space_cache, start, end, GFP_NOFS); } + + while (!list_empty(&info->space_info)) { + space_info = list_entry(info->space_info.next, + struct btrfs_space_info, + list); + list_del(&space_info->list); + kfree(space_info); + } + return 0; } diff --git a/volumes.c b/volumes.c index 581c298..37b0074 100644 --- a/volumes.c +++ b/volumes.c @@ -959,6 +959,20 @@ void btrfs_mapping_init(struct btrfs_mapping_tree *tree) cache_tree_init(&tree->cache_tree); } +void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree) +{ + struct cache_extent *cache; + struct rb_node *node; + struct map_lookup *map; + + while ((node = rb_last(&tree->cache_tree.root)) != NULL) { + cache = rb_entry(node, struct cache_extent, rb_node); + map = container_of(cache, struct map_lookup, ce); + remove_cache_extent(&tree->cache_tree, cache); + free(map); + } +} + int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len) { struct cache_extent *ce; @@ -1486,7 +1500,7 @@ int btrfs_read_sys_array(struct btrfs_root *root) if (!sb) return -ENOMEM; btrfs_set_buffer_uptodate(sb); - write_extent_buffer(sb, super_copy, 0, BTRFS_SUPER_INFO_SIZE); + write_extent_buffer(sb, super_copy, 0, sizeof(*super_copy)); array_size = btrfs_super_sys_array_size(super_copy); /* diff --git a/volumes.h b/volumes.h index 9ff6182..ce1e413 100644 --- a/volumes.h +++ b/volumes.h @@ -182,4 +182,5 @@ int btrfs_add_system_chunk(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_key *key, struct btrfs_chunk *chunk, int item_size); int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); +void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); #endif -- 1.8.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Gene Czarcinski
2013-Jan-19 18:06 UTC
[PATCH 5/6] Btrfs-progs: add btrfs device ready command
From: Josef Bacik <jbacik@fusionio.com> This command will be used by things like dracut that wish to know very simply if all of the devices have been added to the kernel cache yet for the device to be fully mounted. This keeps initrd''s from constantly having to try to mount the file system until it succeeds every time a device is added to the system. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Gene Czarcinski <gene@czarc.net> --- cmds-device.c | 35 +++++++++++++++++++++++++++++++++++ ioctl.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/cmds-device.c b/cmds-device.c index 4787aca..75ee293 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -250,11 +250,46 @@ static int cmd_scan_dev(int argc, char **argv) return 0; } +static const char * const cmd_ready_dev_usage[] = { + "btrfs device ready <device>", + "Check device to see if it has all of it''s devices in cache for mounting", + NULL +}; + +static int cmd_ready_dev(int argc, char **argv) +{ + struct btrfs_ioctl_vol_args args; + int fd; + int ret; + + if (check_argc_min(argc, 2)) + usage(cmd_ready_dev_usage); + + fd = open("/dev/btrfs-control", O_RDWR); + if (fd < 0) { + perror("failed to open /dev/btrfs-control"); + return 10; + } + + strncpy(args.name, argv[argc - 1], BTRFS_PATH_NAME_MAX); + ret = ioctl(fd, BTRFS_IOC_DEVICES_READY, &args); + if (ret < 0) { + fprintf(stderr, "ERROR: unable to determine if the device ''%s''" + " is ready for mounting - %s\n", argv[argc - 1], + strerror(errno)); + ret = 1; + } + + close(fd); + return ret; +} + const struct cmd_group device_cmd_group = { device_cmd_group_usage, NULL, { { "add", cmd_add_dev, cmd_add_dev_usage, NULL, 0 }, { "delete", cmd_rm_dev, cmd_rm_dev_usage, NULL, 0 }, { "scan", cmd_scan_dev, cmd_scan_dev_usage, NULL, 0 }, + { "ready", cmd_ready_dev, cmd_ready_dev_usage, NULL, 0 }, { 0, 0, 0, 0, 0 } } }; diff --git a/ioctl.h b/ioctl.h index 6fda3a1..d32e22c 100644 --- a/ioctl.h +++ b/ioctl.h @@ -419,6 +419,8 @@ struct btrfs_ioctl_clone_range_args { struct btrfs_ioctl_ino_path_args) #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \ struct btrfs_ioctl_ino_path_args) +#define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \ + struct btrfs_ioctl_vol_args) #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \ struct btrfs_ioctl_received_subvol_args) -- 1.8.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Gene Czarcinski
2013-Jan-19 18:06 UTC
[PATCH 6/6] Btrfs-progs: detect if the disk we are formatting is a ssd
Patch rebased because of changes in mkfs.c but otherwise the same as created by Josef Bacik SSD''s do not gain anything by having metadata DUP turned on. The underlying file system that is a part of all SSD''s could easily map duplicate metadat blocks into the same erase block which effectively eliminates the benefit of duplicating the metadata on disk. So detect if we are formatting a single SSD drive and if we are do not use DUP. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Gene Czarcinski <gene@czarc.net> --- Makefile | 2 +- man/mkfs.btrfs.8.in | 5 ++++- mkfs.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 4894903..c7fd97d 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ btrfsck: $(objects) btrfsck.o $(CC) $(CFLAGS) -o btrfsck btrfsck.o $(objects) $(LDFLAGS) $(LIBS) mkfs.btrfs: $(objects) mkfs.o - $(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS) + $(CC) $(CFLAGS) -o mkfs.btrfs $(objects) mkfs.o $(LDFLAGS) $(LIBS) -lblkid btrfs-debug-tree: $(objects) debug-tree.o $(CC) $(CFLAGS) -o btrfs-debug-tree $(objects) debug-tree.o $(LDFLAGS) $(LIBS) diff --git a/man/mkfs.btrfs.8.in b/man/mkfs.btrfs.8.in index 72025ed..b7bcc1b 100644 --- a/man/mkfs.btrfs.8.in +++ b/man/mkfs.btrfs.8.in @@ -47,7 +47,10 @@ Specify a label for the filesystem. .TP \fB\-m\fR, \fB\-\-metadata \fIprofile\fR Specify how metadata must be spanned across the devices specified. Valid -values are raid0, raid1, raid10 or single. +values are raid0, raid1, raid10, single or dup. Single device will have dup +set by default except in the case of SSDs which will default to single. This is +because SSDs can remap blocks internally so duplicate blocks could end up in the +same erase block which negates the benefits of doing metadata duplication. .TP \fB\-M\fR, \fB\-\-mixed\fR Mix data and metadata chunks together for more efficient space diff --git a/mkfs.c b/mkfs.c index 8c291c9..b500ea0 100644 --- a/mkfs.c +++ b/mkfs.c @@ -39,6 +39,7 @@ #include <linux/fs.h> #include <ctype.h> #include <attr/xattr.h> +#include <blkid/blkid.h> #include "ctree.h" #include "disk-io.h" #include "volumes.h" @@ -204,7 +205,7 @@ static int create_one_raid_group(struct btrfs_trans_handle *trans, static int create_raid_groups(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 data_profile, int data_profile_opt, u64 metadata_profile, - int metadata_profile_opt, int mixed) + int metadata_profile_opt, int mixed, int ssd) { u64 num_devices = btrfs_super_num_devices(&root->fs_info->super_copy); u64 allowed; @@ -215,8 +216,12 @@ static int create_raid_groups(struct btrfs_trans_handle *trans, * For mixed groups defaults are single/single. */ if (!metadata_profile_opt && !mixed) { + if (num_devices == 1 && ssd) + printf("Detected a SSD, turning off metadata " + "duplication. Mkfs with -m dup if you want to " + "force metadata duplication.\n"); metadata_profile = (num_devices > 1) ? - BTRFS_BLOCK_GROUP_RAID1 : BTRFS_BLOCK_GROUP_DUP; + BTRFS_BLOCK_GROUP_RAID1 : (ssd) ? 0: BTRFS_BLOCK_GROUP_DUP; } if (!data_profile_opt && !mixed) { data_profile = (num_devices > 1) ? @@ -1186,6 +1191,54 @@ static int check_leaf_or_node_size(u32 size, u32 sectorsize) return 0; } +static int is_ssd(const char *file) +{ + char *devname; + blkid_probe probe; + char *dev; + char path[PATH_MAX]; + dev_t disk; + int fd; + char rotational; + + probe = blkid_new_probe_from_filename(file); + if (!probe) + return 0; + + /* + * We want to use blkid_devno_to_wholedisk() but it''s broken for some + * reason on F17 at least so we''ll do this trickery + */ + disk = blkid_probe_get_wholedisk_devno(probe); + if (!disk) + return 0; + + devname = blkid_devno_to_devname(disk); + if (!devname) + return 0; + + dev = strrchr(devname, ''/''); + dev++; + + snprintf(path, PATH_MAX, "/sys/block/%s/queue/rotational", dev); + + free(devname); + blkid_free_probe(probe); + + fd = open(path, O_RDONLY); + if (fd < 0) { + return 0; + } + + if (read(fd, &rotational, sizeof(char)) < sizeof(char)) { + close(fd); + return 0; + } + close(fd); + + return !atoi((const char *)&rotational); +} + int main(int ac, char **av) { char *file; @@ -1212,6 +1265,7 @@ int main(int ac, char **av) int data_profile_opt = 0; int metadata_profile_opt = 0; int nodiscard = 0; + int ssd = 0; char *source_dir = NULL; int source_dir_set = 0; @@ -1331,6 +1385,9 @@ int main(int ac, char **av) exit(1); } } + + ssd = is_ssd(file); + if (mixed) { if (metadata_profile != data_profile) { fprintf(stderr, "With mixed block groups data and metadata " @@ -1416,7 +1473,7 @@ raid_groups: if (!source_dir_set) { ret = create_raid_groups(trans, root, data_profile, data_profile_opt, metadata_profile, - metadata_profile_opt, mixed); + metadata_profile_opt, mixed, ssd); BUG_ON(ret); } -- 1.8.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Brendan Hide
2013-Jan-19 21:14 UTC
Re: [PATCH 6/6] Btrfs-progs: detect if the disk we are formatting is a ssd
On 2013/01/19 08:06 PM, Gene Czarcinski wrote:> Signed-off-by: Josef Bacik <jbacik@fusionio.com> > Signed-off-by: Gene Czarcinski <gene@czarc.net> > --- > -values are raid0, raid1, raid10 or single. > +values are raid0, raid1, raid10, single or dup. Single device will have dup > +set by default except in the case of SSDs which will default to single. This is > +because SSDs can remap blocks internally so duplicate blocks could end up in the > +same erase block which negates the benefits of doing metadata duplication.Can''t help but suggest that a "NO_DEDUP" command could be added to the SATA Transport Protocol/SCSI Command set. Not sure where to submit that idea ... :-/ -- Brendan Hide http://swiftspirit.co.za/ -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2013-Jan-21 13:01 UTC
Re: [PATCH 6/6] Btrfs-progs: detect if the disk we are formatting is a ssd
On Sat, Jan 19, 2013 at 11:14:09PM +0200, Brendan Hide wrote:> On 2013/01/19 08:06 PM, Gene Czarcinski wrote: > >Signed-off-by: Josef Bacik <jbacik@fusionio.com> > >Signed-off-by: Gene Czarcinski <gene@czarc.net> > >--- > >-values are raid0, raid1, raid10 or single. > >+values are raid0, raid1, raid10, single or dup. Single device will have dup > >+set by default except in the case of SSDs which will default to single. This is > >+because SSDs can remap blocks internally so duplicate blocks could end up in the > >+same erase block which negates the benefits of doing metadata duplication. > Can''t help but suggest that a "NO_DEDUP" command could be added to the SATA > Transport Protocol/SCSI Command set. Not sure where to submit that idea ... > :-/You might get your answer from lkml, fsdevel or linux-scsi. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
I believe that this if the likely source of this patch: http://article.gmane.org/gmane.comp.file-systems.btrfs/4547 I do wonder how much this is still applicable. However, it has been in the btrfs-progs package for Fedora 15, 16, 17, and 18 plus likely some versions of RHEL. On 01/19/2013 01:06 PM, Gene Czarcinski wrote:> Signed-off-by: Gene Czarcinski <gene@czarc.net> > --- > btrfsck.c | 2 ++ > mkfs.c | 4 ++-- > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/btrfsck.c b/btrfsck.c > index a851008..6274ff7 100644 > --- a/btrfsck.c > +++ b/btrfsck.c > @@ -22,7 +22,9 @@ > #include <stdlib.h> > #include <unistd.h> > #include <fcntl.h> > +#include <sys/types.h> > #include <sys/stat.h> > +#include <unistd.h> > #include <getopt.h> > #include "kerncompat.h" > #include "ctree.h" > diff --git a/mkfs.c b/mkfs.c > index fbf8319..d123d5f 100644 > --- a/mkfs.c > +++ b/mkfs.c > @@ -1206,7 +1206,7 @@ int main(int ac, char **av) > u64 alloc_start = 0; > u64 metadata_profile = 0; > u64 data_profile = 0; > - u32 leafsize = getpagesize(); > + u32 leafsize = sysconf(_SC_PAGESIZE); > u32 sectorsize = 4096; > u32 nodesize = leafsize; > u32 stripesize = 4096; > @@ -1282,7 +1282,7 @@ int main(int ac, char **av) > print_usage(); > } > } > - sectorsize = max(sectorsize, (u32)getpagesize()); > + sectorsize = max(sectorsize, (u32)sysconf(_SC_PAGESIZE)); > if (check_leaf_or_node_size(leafsize, sectorsize)) > exit(1); > if (check_leaf_or_node_size(nodesize, sectorsize))-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Here is the source of this patch: http://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg01850.html and the update that is the current patch: http://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg01851.html Gene On 01/19/2013 01:06 PM, Gene Czarcinski wrote:> Signed-off-by: Gene Czarcinski <gene@czarc.net> > --- > mkfs.c | 7 ------- > 1 file changed, 7 deletions(-) > > diff --git a/mkfs.c b/mkfs.c > index d123d5f..8c291c9 100644 > --- a/mkfs.c > +++ b/mkfs.c > @@ -352,7 +352,6 @@ static u64 parse_profile(char *s) > > static char *parse_label(char *input) > { > - int i; > int len = strlen(input); > > if (len >= BTRFS_LABEL_SIZE) { > @@ -360,12 +359,6 @@ static char *parse_label(char *input) > BTRFS_LABEL_SIZE - 1); > exit(1); > } > - for (i = 0; i < len; i++) { > - if (input[i] == ''/'' || input[i] == ''\\'') { > - fprintf(stderr, "invalid label %s\n", input); > - exit(1); > - } > - } > return strdup(input); > } >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Finally, here is the source for this patch: http://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg02659.html On 01/19/2013 01:06 PM, Gene Czarcinski wrote:> A small part of this patch proved unnecessary because it was > already corrected by the plug a memory leak reported by cppcheck > patch. > > Signed-off-by: Gene Czarcinski <gene@czarc.net> > --- > disk-io.c | 16 +++++++++++----- > extent-cache.c | 11 +++++++++++ > extent-cache.h | 1 + > extent-tree.c | 10 ++++++++++ > volumes.c | 16 +++++++++++++++- > volumes.h | 1 + > 6 files changed, 49 insertions(+), 6 deletions(-) > > diff --git a/disk-io.c b/disk-io.c > index c4d4631..5b6c6b1 100644 > --- a/disk-io.c > +++ b/disk-io.c > @@ -631,7 +631,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, > struct btrfs_root *chunk_root = malloc(sizeof(struct btrfs_root)); > struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root)); > struct btrfs_root *csum_root = malloc(sizeof(struct btrfs_root)); > - struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info)); > + struct btrfs_fs_info *fs_info = malloc(sizeof(struct btrfs_fs_info)); > int ret; > struct btrfs_super_block *disk_super; > struct btrfs_fs_devices *fs_devices = NULL; > @@ -655,7 +655,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, > goto out; > } > > - memset(fs_info, 0, sizeof(*fs_info)); > + memset(fs_info, 0, sizeof(struct btrfs_fs_info)); > fs_info->tree_root = tree_root; > fs_info->extent_root = extent_root; > fs_info->chunk_root = chunk_root; > @@ -1084,15 +1084,19 @@ static int close_all_devices(struct btrfs_fs_info *fs_info) > { > struct list_head *list; > struct list_head *next; > + struct list_head *tmp; > struct btrfs_device *device; > > - return 0; > - > list = &fs_info->fs_devices->devices; > - list_for_each(next, list) { > + list_for_each_safe(next, tmp, list) { > device = list_entry(next, struct btrfs_device, dev_list); > close(device->fd); > + list_del(&device->dev_list); > + free(device->name); > + free(device->label); > + free(device); > } > + free(fs_info->fs_devices); > return 0; > } > > @@ -1142,12 +1146,14 @@ int close_ctree(struct btrfs_root *root) > extent_io_tree_cleanup(&fs_info->pinned_extents); > extent_io_tree_cleanup(&fs_info->pending_del); > extent_io_tree_cleanup(&fs_info->extent_ins); > + btrfs_mapping_tree_free(&fs_info->mapping_tree); > > free(fs_info->tree_root); > free(fs_info->extent_root); > free(fs_info->chunk_root); > free(fs_info->dev_root); > free(fs_info->csum_root); > + free(fs_info->log_root_tree); > free(fs_info); > > return 0; > diff --git a/extent-cache.c b/extent-cache.c > index 3dd6434..84d4bbc 100644 > --- a/extent-cache.c > +++ b/extent-cache.c > @@ -168,3 +168,14 @@ void remove_cache_extent(struct cache_tree *tree, > rb_erase(&pe->rb_node, &tree->root); > } > > +void free_cache_tree(struct cache_tree *tree) > +{ > + struct rb_node *node; > + struct cache_extent *cache; > + > + while ((node = rb_last(&tree->root)) != NULL) { > + cache = rb_entry(node, struct cache_extent, rb_node); > + remove_cache_extent(tree, cache); > + free(cache); > + } > +} > diff --git a/extent-cache.h b/extent-cache.h > index 7f2f2a6..1696bc2 100644 > --- a/extent-cache.h > +++ b/extent-cache.h > @@ -43,6 +43,7 @@ struct cache_extent *find_cache_extent(struct cache_tree *tree, > int insert_cache_extent(struct cache_tree *tree, u64 start, u64 size); > int insert_existing_cache_extent(struct cache_tree *tree, > struct cache_extent *pe); > +void free_cache_tree(struct cache_tree *tree); > > static inline int cache_tree_empty(struct cache_tree *tree) > { > diff --git a/extent-tree.c b/extent-tree.c > index 20cdffa..d644d9a 100644 > --- a/extent-tree.c > +++ b/extent-tree.c > @@ -2999,6 +2999,7 @@ out: > > int btrfs_free_block_groups(struct btrfs_fs_info *info) > { > + struct btrfs_space_info *space_info; > u64 start; > u64 end; > u64 ptr; > @@ -3022,6 +3023,15 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) > clear_extent_dirty(&info->free_space_cache, start, > end, GFP_NOFS); > } > + > + while (!list_empty(&info->space_info)) { > + space_info = list_entry(info->space_info.next, > + struct btrfs_space_info, > + list); > + list_del(&space_info->list); > + kfree(space_info); > + } > + > return 0; > } > > diff --git a/volumes.c b/volumes.c > index 581c298..37b0074 100644 > --- a/volumes.c > +++ b/volumes.c > @@ -959,6 +959,20 @@ void btrfs_mapping_init(struct btrfs_mapping_tree *tree) > cache_tree_init(&tree->cache_tree); > } > > +void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree) > +{ > + struct cache_extent *cache; > + struct rb_node *node; > + struct map_lookup *map; > + > + while ((node = rb_last(&tree->cache_tree.root)) != NULL) { > + cache = rb_entry(node, struct cache_extent, rb_node); > + map = container_of(cache, struct map_lookup, ce); > + remove_cache_extent(&tree->cache_tree, cache); > + free(map); > + } > +} > + > int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len) > { > struct cache_extent *ce; > @@ -1486,7 +1500,7 @@ int btrfs_read_sys_array(struct btrfs_root *root) > if (!sb) > return -ENOMEM; > btrfs_set_buffer_uptodate(sb); > - write_extent_buffer(sb, super_copy, 0, BTRFS_SUPER_INFO_SIZE); > + write_extent_buffer(sb, super_copy, 0, sizeof(*super_copy)); > array_size = btrfs_super_sys_array_size(super_copy); > > /* > diff --git a/volumes.h b/volumes.h > index 9ff6182..ce1e413 100644 > --- a/volumes.h > +++ b/volumes.h > @@ -182,4 +182,5 @@ int btrfs_add_system_chunk(struct btrfs_trans_handle *trans, > struct btrfs_root *root, struct btrfs_key *key, > struct btrfs_chunk *chunk, int item_size); > int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); > +void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); > #endif-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Gene Czarcinski
2013-Jan-22 21:56 UTC
Re: [PATCH 1/6] Fedora 18 - btrfs-init-dev-list.patch
I could not find a source for this patch on the mailing list On 01/19/2013 01:06 PM, Gene Czarcinski wrote:> Signed-off-by: Gene Czarcinski <gene@czarc.net> > --- > utils.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/utils.c b/utils.c > index 938f9a5..51b78d5 100644 > --- a/utils.c > +++ b/utils.c > @@ -477,7 +477,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, > u64 num_devs; > int ret; > > - device = kmalloc(sizeof(*device), GFP_NOFS); > + device = kzalloc(sizeof(*device), GFP_NOFS); > if (!device) > return -ENOMEM; > buf = kmalloc(sectorsize, GFP_NOFS); > @@ -503,6 +503,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, > device->bytes_used = 0; > device->total_ios = 0; > device->dev_root = root->fs_info->dev_root; > + INIT_LIST_HEAD(&device->dev_list); > > ret = btrfs_add_device(trans, root, device); > BUG_ON(ret);-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Chris Samuel
2013-Jan-23 02:35 UTC
Re: [PATCH 6/6] Btrfs-progs: detect if the disk we are formatting is a ssd
On 20/01/13 08:14, Brendan Hide wrote:> Can''t help but suggest that a "NO_DEDUP" command could be added to the > SATA Transport Protocol/SCSI Command set. Not sure where to submit that > idea ... :-/Serial ATA International Organization (SATA-IO) maintain the specs for SATA. Looks like membership is limited to companies and costs US$1,700 a year. http://sata-io.org/ SCSI is from the T10 committee: http://www.t10.org/ The intro page indicates it''s a fairly open group: # T10 operates under INCITS and is responsible for SCSI Storage # Interfaces. Its principal work is the Small Computer System # Interface (SCSI), including the family of SCSI-3 projects. # Anyone "directly and materially affected" is welcome to # participate on T10 (essentially, this amounts to anyone # interested in T10''s work). cheers, Chris -- Chris Samuel : http://www.csamuel.org/ : Melbourne, VIC -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jan 22, 2013 at 04:25:44PM -0500, Gene Czarcinski wrote:> I believe that this if the likely source of this patch: > http://article.gmane.org/gmane.comp.file-systems.btrfs/4547Thanks for the pointer.> I do wonder how much this is still applicable. However, it has been in the > btrfs-progs package for Fedora 15, 16, 17, and 18 plus likely some versions > of RHEL.man getpagesize: "Portable applications should employ sysconf(_SC_PAGESIZE) instead of getpagesize()" added with the original changelog and s-o-b, modified the subject line to say "Use sysconf instead of getpagesize". david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 1/19/13 12:06 PM, Gene Czarcinski wrote:> A small part of this patch proved unnecessary because it was > already corrected by the plug a memory leak reported by cppcheck > patch.Thanks Gene - I''d kind of like to hold off on this one (just in case it was on the verge of being merged) because Zach & I are going through some coverity scans which will probably overlap with this, and might actually be reviewable/bisectable/attributable etc. :) Thanks, -Eric> Signed-off-by: Gene Czarcinski <gene@czarc.net> > --- > disk-io.c | 16 +++++++++++----- > extent-cache.c | 11 +++++++++++ > extent-cache.h | 1 + > extent-tree.c | 10 ++++++++++ > volumes.c | 16 +++++++++++++++- > volumes.h | 1 + > 6 files changed, 49 insertions(+), 6 deletions(-) > > diff --git a/disk-io.c b/disk-io.c > index c4d4631..5b6c6b1 100644 > --- a/disk-io.c > +++ b/disk-io.c > @@ -631,7 +631,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, > struct btrfs_root *chunk_root = malloc(sizeof(struct btrfs_root)); > struct btrfs_root *dev_root = malloc(sizeof(struct btrfs_root)); > struct btrfs_root *csum_root = malloc(sizeof(struct btrfs_root)); > - struct btrfs_fs_info *fs_info = malloc(sizeof(*fs_info)); > + struct btrfs_fs_info *fs_info = malloc(sizeof(struct btrfs_fs_info)); > int ret; > struct btrfs_super_block *disk_super; > struct btrfs_fs_devices *fs_devices = NULL; > @@ -655,7 +655,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, > goto out; > } > > - memset(fs_info, 0, sizeof(*fs_info)); > + memset(fs_info, 0, sizeof(struct btrfs_fs_info)); > fs_info->tree_root = tree_root; > fs_info->extent_root = extent_root; > fs_info->chunk_root = chunk_root; > @@ -1084,15 +1084,19 @@ static int close_all_devices(struct btrfs_fs_info *fs_info) > { > struct list_head *list; > struct list_head *next; > + struct list_head *tmp; > struct btrfs_device *device; > > - return 0; > - > list = &fs_info->fs_devices->devices; > - list_for_each(next, list) { > + list_for_each_safe(next, tmp, list) { > device = list_entry(next, struct btrfs_device, dev_list); > close(device->fd); > + list_del(&device->dev_list); > + free(device->name); > + free(device->label); > + free(device); > } > + free(fs_info->fs_devices); > return 0; > } > > @@ -1142,12 +1146,14 @@ int close_ctree(struct btrfs_root *root) > extent_io_tree_cleanup(&fs_info->pinned_extents); > extent_io_tree_cleanup(&fs_info->pending_del); > extent_io_tree_cleanup(&fs_info->extent_ins); > + btrfs_mapping_tree_free(&fs_info->mapping_tree); > > free(fs_info->tree_root); > free(fs_info->extent_root); > free(fs_info->chunk_root); > free(fs_info->dev_root); > free(fs_info->csum_root); > + free(fs_info->log_root_tree); > free(fs_info); > > return 0; > diff --git a/extent-cache.c b/extent-cache.c > index 3dd6434..84d4bbc 100644 > --- a/extent-cache.c > +++ b/extent-cache.c > @@ -168,3 +168,14 @@ void remove_cache_extent(struct cache_tree *tree, > rb_erase(&pe->rb_node, &tree->root); > } > > +void free_cache_tree(struct cache_tree *tree) > +{ > + struct rb_node *node; > + struct cache_extent *cache; > + > + while ((node = rb_last(&tree->root)) != NULL) { > + cache = rb_entry(node, struct cache_extent, rb_node); > + remove_cache_extent(tree, cache); > + free(cache); > + } > +} > diff --git a/extent-cache.h b/extent-cache.h > index 7f2f2a6..1696bc2 100644 > --- a/extent-cache.h > +++ b/extent-cache.h > @@ -43,6 +43,7 @@ struct cache_extent *find_cache_extent(struct cache_tree *tree, > int insert_cache_extent(struct cache_tree *tree, u64 start, u64 size); > int insert_existing_cache_extent(struct cache_tree *tree, > struct cache_extent *pe); > +void free_cache_tree(struct cache_tree *tree); > > static inline int cache_tree_empty(struct cache_tree *tree) > { > diff --git a/extent-tree.c b/extent-tree.c > index 20cdffa..d644d9a 100644 > --- a/extent-tree.c > +++ b/extent-tree.c > @@ -2999,6 +2999,7 @@ out: > > int btrfs_free_block_groups(struct btrfs_fs_info *info) > { > + struct btrfs_space_info *space_info; > u64 start; > u64 end; > u64 ptr; > @@ -3022,6 +3023,15 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) > clear_extent_dirty(&info->free_space_cache, start, > end, GFP_NOFS); > } > + > + while (!list_empty(&info->space_info)) { > + space_info = list_entry(info->space_info.next, > + struct btrfs_space_info, > + list); > + list_del(&space_info->list); > + kfree(space_info); > + } > + > return 0; > } > > diff --git a/volumes.c b/volumes.c > index 581c298..37b0074 100644 > --- a/volumes.c > +++ b/volumes.c > @@ -959,6 +959,20 @@ void btrfs_mapping_init(struct btrfs_mapping_tree *tree) > cache_tree_init(&tree->cache_tree); > } > > +void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree) > +{ > + struct cache_extent *cache; > + struct rb_node *node; > + struct map_lookup *map; > + > + while ((node = rb_last(&tree->cache_tree.root)) != NULL) { > + cache = rb_entry(node, struct cache_extent, rb_node); > + map = container_of(cache, struct map_lookup, ce); > + remove_cache_extent(&tree->cache_tree, cache); > + free(map); > + } > +} > + > int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len) > { > struct cache_extent *ce; > @@ -1486,7 +1500,7 @@ int btrfs_read_sys_array(struct btrfs_root *root) > if (!sb) > return -ENOMEM; > btrfs_set_buffer_uptodate(sb); > - write_extent_buffer(sb, super_copy, 0, BTRFS_SUPER_INFO_SIZE); > + write_extent_buffer(sb, super_copy, 0, sizeof(*super_copy)); > array_size = btrfs_super_sys_array_size(super_copy); > > /* > diff --git a/volumes.h b/volumes.h > index 9ff6182..ce1e413 100644 > --- a/volumes.h > +++ b/volumes.h > @@ -182,4 +182,5 @@ int btrfs_add_system_chunk(struct btrfs_trans_handle *trans, > struct btrfs_root *root, struct btrfs_key *key, > struct btrfs_chunk *chunk, int item_size); > int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); > +void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree); > #endif >-- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html