From patchwork Wed May 14 01:18:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 4171871 X-Patchwork-Delegate: dave@jikos.cz Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8F90FBFF02 for ; Wed, 14 May 2014 01:18:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1B0DE202E5 for ; Wed, 14 May 2014 01:18:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7EC8A20306 for ; Wed, 14 May 2014 01:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751527AbaENBSP (ORCPT ); Tue, 13 May 2014 21:18:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45126 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750750AbaENBSP (ORCPT ); Tue, 13 May 2014 21:18:15 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4E1IEx1008022 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 May 2014 21:18:14 -0400 Received: from liberator.sandeen.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4E1IDOJ018123 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 13 May 2014 21:18:14 -0400 Message-ID: <5372C457.3000706@redhat.com> Date: Tue, 13 May 2014 20:18:15 -0500 From: Eric Sandeen User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: linux-btrfs CC: jshubin@redhat.com Subject: [PATCH] mkfs.btrfs: allow UUID specification at mkfs time X-Enigmail-Version: 1.6 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow the specification of the filesystem UUID at mkfs time. (Implemented only for mkfs.btrfs, not btrfs-convert). Signed-off-by: Eric Sandeen --- -- 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 diff --git a/btrfs-convert.c b/btrfs-convert.c index a8b2c51..d62d4f8 100644 --- a/btrfs-convert.c +++ b/btrfs-convert.c @@ -2240,7 +2240,7 @@ static int do_convert(const char *devname, int datacsum, int packing, goto fail; } ret = make_btrfs(fd, devname, ext2_fs->super->s_volume_name, - blocks, total_bytes, blocksize, blocksize, + NULL, blocks, total_bytes, blocksize, blocksize, blocksize, blocksize, 0); if (ret) { fprintf(stderr, "unable to create initial ctree: %s\n", diff --git a/man/mkfs.btrfs.8.in b/man/mkfs.btrfs.8.in index bef509d..4450d03 100644 --- a/man/mkfs.btrfs.8.in +++ b/man/mkfs.btrfs.8.in @@ -16,6 +16,7 @@ mkfs.btrfs \- create a btrfs filesystem [ \fB\-r\fP\fI rootdir\fP ] [ \fB\-K\fP ] [ \fB\-O\fP\fI feature1,feature2,...\fP ] +[ \fB\-U\fP\fI uuid\fP ] [ \fB\-h\fP ] [ \fB\-V\fP ] \fI device\fP [ \fIdevice ...\fP ] @@ -90,6 +91,9 @@ To see all run \fBmkfs.btrfs -O list-all\fR .TP +\fB\-U\fR, \fB\-\-uuid \fR +Create the filesystem with the specified UUID. +.TP \fB\-V\fR, \fB\-\-version\fR Print the \fBmkfs.btrfs\fP version and exit. .SH UNIT diff --git a/mkfs.c b/mkfs.c index dbd83f5..eccb08f 100644 --- a/mkfs.c +++ b/mkfs.c @@ -288,6 +288,7 @@ static void print_usage(void) fprintf(stderr, "\t -r --rootdir the source directory\n"); fprintf(stderr, "\t -K --nodiscard do not perform whole device TRIM\n"); fprintf(stderr, "\t -O --features comma separated list of filesystem features\n"); + fprintf(stderr, "\t -U --uuid specify the filesystem UUID\n"); fprintf(stderr, "\t -V --version print the mkfs.btrfs version and exit\n"); fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION); exit(1); @@ -351,6 +352,7 @@ static struct option long_options[] = { { "rootdir", 1, NULL, 'r' }, { "nodiscard", 0, NULL, 'K' }, { "features", 0, NULL, 'O' }, + { "uuid", 0, NULL, 'U' }, { NULL, 0, NULL, 0} }; @@ -1273,11 +1275,12 @@ int main(int ac, char **av) int dev_cnt = 0; int saved_optind; char estr[100]; + char *fs_uuid = NULL; u64 features = DEFAULT_MKFS_FEATURES; while(1) { int c; - c = getopt_long(ac, av, "A:b:fl:n:s:m:d:L:O:r:VMK", + c = getopt_long(ac, av, "A:b:fl:n:s:m:d:L:O:r:U:VMK", long_options, &option_index); if (c < 0) break; @@ -1346,6 +1349,9 @@ int main(int ac, char **av) source_dir = optarg; source_dir_set = 1; break; + case 'U': + fs_uuid = optarg; + break; case 'K': discard = 0; break; @@ -1514,7 +1520,7 @@ int main(int ac, char **av) process_fs_features(features); - ret = make_btrfs(fd, file, label, blocks, dev_block_count, + ret = make_btrfs(fd, file, label, fs_uuid, blocks, dev_block_count, nodesize, leafsize, sectorsize, stripesize, features); if (ret) { diff --git a/utils.c b/utils.c index 3e9c527..3f46e8f 100644 --- a/utils.c +++ b/utils.c @@ -93,12 +93,12 @@ static u64 reference_root_table[] = { [6] = BTRFS_CSUM_TREE_OBJECTID, }; -int make_btrfs(int fd, const char *device, const char *label, +int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid, u64 blocks[7], u64 num_bytes, u32 nodesize, u32 leafsize, u32 sectorsize, u32 stripesize, u64 features) { struct btrfs_super_block super; - struct extent_buffer *buf; + struct extent_buffer *buf = NULL; struct btrfs_root_item root_item; struct btrfs_disk_key disk_key; struct btrfs_extent_item *extent_item; @@ -125,7 +125,14 @@ int make_btrfs(int fd, const char *device, const char *label, memset(&super, 0, sizeof(super)); num_bytes = (num_bytes / sectorsize) * sectorsize; - uuid_generate(super.fsid); + if (fs_uuid) { + if (uuid_parse(fs_uuid, super.fsid) != 0) { + fprintf(stderr, "could not parse UUID: %s\n", fs_uuid); + ret = -EINVAL; + goto out; + } + } else + uuid_generate(super.fsid); uuid_generate(super.dev_item.uuid); uuid_generate(chunk_tree_uuid); diff --git a/utils.h b/utils.h index 3c62066..054cbb6 100644 --- a/utils.h +++ b/utils.h @@ -40,7 +40,7 @@ #define BTRFS_UUID_UNPARSED_SIZE 37 int make_btrfs(int fd, const char *device, const char *label, - u64 blocks[6], u64 num_bytes, u32 nodesize, + char *fs_uuid, u64 blocks[6], u64 num_bytes, u32 nodesize, u32 leafsize, u32 sectorsize, u32 stripesize, u64 features); int btrfs_make_root_dir(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 objectid);