forked from Mirrors/btrfs-progs
btrfs-progs: mkfs: use preallocated buffers for config uuids
No need for dynamic allocation, the buffers are small, remove the now-useless error conditions. Signed-off-by: David Sterba <dsterba@suse.com>master
parent
90e3e630c2
commit
7aaa1a92f6
|
@ -2373,10 +2373,8 @@ static int do_convert(const char *devname, int datacsum, int packing,
|
||||||
mkfs_cfg.stripesize = blocksize;
|
mkfs_cfg.stripesize = blocksize;
|
||||||
mkfs_cfg.features = features;
|
mkfs_cfg.features = features;
|
||||||
/* New convert need these space */
|
/* New convert need these space */
|
||||||
mkfs_cfg.fs_uuid = malloc(BTRFS_UUID_UNPARSED_SIZE);
|
memset(mkfs_cfg.chunk_uuid, 0, BTRFS_UUID_UNPARSED_SIZE);
|
||||||
mkfs_cfg.chunk_uuid = malloc(BTRFS_UUID_UNPARSED_SIZE);
|
memset(mkfs_cfg.fs_uuid, 0, BTRFS_UUID_UNPARSED_SIZE);
|
||||||
*(mkfs_cfg.fs_uuid) = '\0';
|
|
||||||
*(mkfs_cfg.chunk_uuid) = '\0';
|
|
||||||
|
|
||||||
ret = make_btrfs(fd, &mkfs_cfg, &cctx);
|
ret = make_btrfs(fd, &mkfs_cfg, &cctx);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|
2
mkfs.c
2
mkfs.c
|
@ -1735,7 +1735,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
mkfs_cfg.label = label;
|
mkfs_cfg.label = label;
|
||||||
mkfs_cfg.fs_uuid = fs_uuid;
|
memcpy(mkfs_cfg.fs_uuid, fs_uuid, sizeof(mkfs_cfg.fs_uuid));
|
||||||
memcpy(mkfs_cfg.blocks, blocks, sizeof(blocks));
|
memcpy(mkfs_cfg.blocks, blocks, sizeof(blocks));
|
||||||
mkfs_cfg.num_bytes = dev_block_count;
|
mkfs_cfg.num_bytes = dev_block_count;
|
||||||
mkfs_cfg.nodesize = nodesize;
|
mkfs_cfg.nodesize = nodesize;
|
||||||
|
|
12
utils.c
12
utils.c
|
@ -250,16 +250,10 @@ static int setup_temp_super(int fd, struct btrfs_mkfs_config *cfg,
|
||||||
struct btrfs_super_block *super = (struct btrfs_super_block *)super_buf;
|
struct btrfs_super_block *super = (struct btrfs_super_block *)super_buf;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/*
|
|
||||||
* We rely on cfg->chunk_uuid and cfg->fs_uuid to pass uuid
|
|
||||||
* for other functions.
|
|
||||||
* Caller must allocate space for them
|
|
||||||
*/
|
|
||||||
BUG_ON(!cfg->chunk_uuid || !cfg->fs_uuid);
|
|
||||||
memset(super_buf, 0, BTRFS_SUPER_INFO_SIZE);
|
memset(super_buf, 0, BTRFS_SUPER_INFO_SIZE);
|
||||||
cfg->num_bytes = round_down(cfg->num_bytes, cfg->sectorsize);
|
cfg->num_bytes = round_down(cfg->num_bytes, cfg->sectorsize);
|
||||||
|
|
||||||
if (cfg->fs_uuid && *cfg->fs_uuid) {
|
if (*cfg->fs_uuid) {
|
||||||
if (uuid_parse(cfg->fs_uuid, super->fsid) != 0) {
|
if (uuid_parse(cfg->fs_uuid, super->fsid) != 0) {
|
||||||
error("cound not parse UUID: %s", cfg->fs_uuid);
|
error("cound not parse UUID: %s", cfg->fs_uuid);
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
|
@ -320,8 +314,6 @@ static int setup_temp_extent_buffer(struct extent_buffer *buf,
|
||||||
unsigned char chunk_uuid[BTRFS_UUID_SIZE];
|
unsigned char chunk_uuid[BTRFS_UUID_SIZE];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* We rely on cfg->fs_uuid and chunk_uuid to fsid and chunk uuid */
|
|
||||||
BUG_ON(!cfg->fs_uuid || !cfg->chunk_uuid);
|
|
||||||
ret = uuid_parse(cfg->fs_uuid, fsid);
|
ret = uuid_parse(cfg->fs_uuid, fsid);
|
||||||
if (ret)
|
if (ret)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -1049,7 +1041,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg,
|
||||||
memset(&super, 0, sizeof(super));
|
memset(&super, 0, sizeof(super));
|
||||||
|
|
||||||
num_bytes = (cfg->num_bytes / cfg->sectorsize) * cfg->sectorsize;
|
num_bytes = (cfg->num_bytes / cfg->sectorsize) * cfg->sectorsize;
|
||||||
if (cfg->fs_uuid && *cfg->fs_uuid) {
|
if (*cfg->fs_uuid) {
|
||||||
if (uuid_parse(cfg->fs_uuid, super.fsid) != 0) {
|
if (uuid_parse(cfg->fs_uuid, super.fsid) != 0) {
|
||||||
error("cannot not parse UUID: %s", cfg->fs_uuid);
|
error("cannot not parse UUID: %s", cfg->fs_uuid);
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
|
|
4
utils.h
4
utils.h
|
@ -112,8 +112,8 @@ void btrfs_parse_features_to_string(char *buf, u64 flags);
|
||||||
|
|
||||||
struct btrfs_mkfs_config {
|
struct btrfs_mkfs_config {
|
||||||
char *label;
|
char *label;
|
||||||
char *fs_uuid;
|
char fs_uuid[BTRFS_UUID_UNPARSED_SIZE];
|
||||||
char *chunk_uuid;
|
char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE];
|
||||||
u64 blocks[8];
|
u64 blocks[8];
|
||||||
u64 num_bytes;
|
u64 num_bytes;
|
||||||
u32 nodesize;
|
u32 nodesize;
|
||||||
|
|
Loading…
Reference in New Issue