lvm: don't generate uuid for ext4 snapshots

only btrfs and xfs need it. Closes #2375. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 046c3a1c
...@@ -315,6 +315,11 @@ int lvm_is_thin_pool(const char *path) ...@@ -315,6 +315,11 @@ int lvm_is_thin_pool(const char *path)
return lvm_compare_lv_attr(path, 0, 't'); return lvm_compare_lv_attr(path, 0, 't');
} }
static inline bool fs_needs_new_uuid(const char *fstype)
{
return strcmp(fstype, "xfs") == 0 || strcmp(fstype, "btrfs") == 0;
}
static int lvm_snapshot_create_new_uuid_wrapper(void *data) static int lvm_snapshot_create_new_uuid_wrapper(void *data)
{ {
struct lvcreate_args *args = data; struct lvcreate_args *args = data;
...@@ -330,8 +335,9 @@ static int lvm_snapshot_create_new_uuid_wrapper(void *data) ...@@ -330,8 +335,9 @@ static int lvm_snapshot_create_new_uuid_wrapper(void *data)
static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t size) static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t size)
{ {
__do_free char *pathdup = NULL;
int ret; int ret;
char *lv, *pathdup; char *lv;
char sz[24]; char sz[24];
char fstype[100]; char fstype[100];
char cmd_output[PATH_MAX]; char cmd_output[PATH_MAX];
...@@ -339,24 +345,17 @@ static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t siz ...@@ -339,24 +345,17 @@ static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t siz
const char *origsrc; const char *origsrc;
struct lvcreate_args cmd_args = {0}; struct lvcreate_args cmd_args = {0};
ret = snprintf(sz, 24, "%" PRIu64 "b", size); ret = snprintf(sz, sizeof(sz), "%" PRIu64 "b", size);
if (ret < 0 || ret >= 24) { if (ret < 0 || (size_t)ret >= sizeof(sz))
ERROR("Failed to create string"); return log_error_errno(-EIO, EIO, "Failed to create string");
return -1;
}
pathdup = strdup(path); pathdup = strdup(path);
if (!pathdup) { if (!pathdup)
ERROR("Failed to duplicate string \"%s\"", path); return log_error_errno(-ENOMEM, ENOMEM, "Failed to duplicate string \"%s\"", path);
return -1;
}
lv = strrchr(pathdup, '/'); lv = strrchr(pathdup, '/');
if (!lv) { if (!lv)
ERROR("Failed to detect \"/\" in string \"%s\"", pathdup); return log_error_errno(-ENOENT, ENOENT, "Failed to detect \"/\" in string \"%s\"", pathdup);
free(pathdup);
return -1;
}
repairchar = *lv; repairchar = *lv;
*lv = '\0'; *lv = '\0';
lv++; lv++;
...@@ -368,12 +367,10 @@ static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t siz ...@@ -368,12 +367,10 @@ static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t siz
*/ */
origsrc = lxc_storage_get_path(orig->src, "lvm"); origsrc = lxc_storage_get_path(orig->src, "lvm");
ret = lvm_is_thin_volume(origsrc); ret = lvm_is_thin_volume(origsrc);
if (ret < 0) { if (ret < 0)
free(pathdup);
return -1; return -1;
} else if (ret) { else if (ret)
cmd_args.thinpool = origsrc; cmd_args.thinpool = origsrc;
}
cmd_args.lv = lv; cmd_args.lv = lv;
cmd_args.source_lv = origsrc; cmd_args.source_lv = origsrc;
...@@ -382,17 +379,15 @@ static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t siz ...@@ -382,17 +379,15 @@ static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t siz
origsrc, sz); origsrc, sz);
ret = run_command(cmd_output, sizeof(cmd_output), ret = run_command(cmd_output, sizeof(cmd_output),
lvm_snapshot_exec_wrapper, (void *)&cmd_args); lvm_snapshot_exec_wrapper, (void *)&cmd_args);
if (ret < 0) { if (ret < 0)
ERROR("Failed to create logical volume \"%s\": %s", lv, cmd_output); return log_error_errno(-1, errno, "Failed to create logical volume \"%s\": %s",
free(pathdup); lv, cmd_output);
return -1;
}
if (detect_fs(orig, fstype, 100) < 0) { if (detect_fs(orig, fstype, 100) < 0)
INFO("Failed to detect filesystem type for \"%s\"", origsrc); return log_error_errno(-EINVAL, EINVAL, "Failed to detect filesystem type for \"%s\"", origsrc);
free(pathdup);
return -1; if (!fs_needs_new_uuid(fstype))
} return 0;
/* repair path */ /* repair path */
lv--; lv--;
...@@ -401,13 +396,10 @@ static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t siz ...@@ -401,13 +396,10 @@ static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t siz
cmd_args.fstype = fstype; cmd_args.fstype = fstype;
ret = run_command(cmd_output, sizeof(cmd_output), ret = run_command(cmd_output, sizeof(cmd_output),
lvm_snapshot_create_new_uuid_wrapper, (void *)&cmd_args); lvm_snapshot_create_new_uuid_wrapper, (void *)&cmd_args);
if (ret < 0) { if (ret < 0)
ERROR("Failed to create new uuid for volume \"%s\": %s", pathdup, cmd_output); return log_error_errno(-1, errno, "Failed to create new uuid for volume \"%s\": %s",
free(pathdup); pathdup, cmd_output);
return -1;
}
free(pathdup);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment