mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-27 11:13:50 +00:00
allow site-wide customization of zfsroot and lvm vg
/etc/lxc/lxc.conf can contain zfsroot = custom1 lvm_vg = vg0 (Otherwise the defaults are 'lxc' for lvm_vg, and 'lxc' for zfsroot) Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
parent
ca52dcb559
commit
31a95fecd2
@ -492,34 +492,33 @@ static int zfs_clone(const char *opath, const char *npath, const char *oname,
|
|||||||
{
|
{
|
||||||
// use the 'zfs list | grep opath' entry to get the zfsroot
|
// use the 'zfs list | grep opath' entry to get the zfsroot
|
||||||
char output[MAXPATHLEN], option[MAXPATHLEN], *p;
|
char output[MAXPATHLEN], option[MAXPATHLEN], *p;
|
||||||
|
const char *zfsroot = output;
|
||||||
int ret;
|
int ret;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
if (!zfs_list_entry(opath, output))
|
if (zfs_list_entry(opath, output)) {
|
||||||
// default is tank. I'd prefer lxc, but apparently this is
|
// zfsroot is output up to ' '
|
||||||
// tradition.
|
if ((p = index(output, ' ')) == NULL)
|
||||||
sprintf(output, "tank");
|
return -1;
|
||||||
|
*p = '\0';
|
||||||
if ((p = index(output, ' ')) == NULL)
|
if ((p = rindex(output, '/')) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if ((p = rindex(output, '/')) == NULL)
|
} else
|
||||||
return -1;
|
zfsroot = default_zfs_root();
|
||||||
*p = '\0';
|
|
||||||
|
|
||||||
ret = snprintf(option, MAXPATHLEN, "-omountpoint=%s/%s/rootfs",
|
ret = snprintf(option, MAXPATHLEN, "-omountpoint=%s/%s/rootfs",
|
||||||
lxcpath, nname);
|
lxcpath, nname);
|
||||||
if (ret < 0 || ret >= MAXPATHLEN)
|
if (ret < 0 || ret >= MAXPATHLEN)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// zfsroot is output up to ' '
|
|
||||||
// zfs create -omountpoint=$lxcpath/$lxcname $zfsroot/$nname
|
// zfs create -omountpoint=$lxcpath/$lxcname $zfsroot/$nname
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
if ((pid = fork()) < 0)
|
if ((pid = fork()) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
char dev[MAXPATHLEN];
|
char dev[MAXPATHLEN];
|
||||||
ret = snprintf(dev, MAXPATHLEN, "%s/%s", output, nname);
|
ret = snprintf(dev, MAXPATHLEN, "%s/%s", zfsroot, nname);
|
||||||
if (ret < 0 || ret >= MAXPATHLEN)
|
if (ret < 0 || ret >= MAXPATHLEN)
|
||||||
exit(1);
|
exit(1);
|
||||||
execlp("zfs", "zfs", "create", option, dev, NULL);
|
execlp("zfs", "zfs", "create", option, dev, NULL);
|
||||||
@ -532,11 +531,11 @@ static int zfs_clone(const char *opath, const char *npath, const char *oname,
|
|||||||
// zfs clone zfsroot/oname@nname zfsroot/nname
|
// zfs clone zfsroot/oname@nname zfsroot/nname
|
||||||
char path1[MAXPATHLEN], path2[MAXPATHLEN];
|
char path1[MAXPATHLEN], path2[MAXPATHLEN];
|
||||||
|
|
||||||
ret = snprintf(path1, MAXPATHLEN, "%s/%s@%s", output,
|
ret = snprintf(path1, MAXPATHLEN, "%s/%s@%s", zfsroot,
|
||||||
oname, nname);
|
oname, nname);
|
||||||
if (ret < 0 || ret >= MAXPATHLEN)
|
if (ret < 0 || ret >= MAXPATHLEN)
|
||||||
return -1;
|
return -1;
|
||||||
(void) snprintf(path2, MAXPATHLEN, "%s/%s", output, nname);
|
(void) snprintf(path2, MAXPATHLEN, "%s/%s", zfsroot, nname);
|
||||||
|
|
||||||
// if the snapshot exists, delete it
|
// if the snapshot exists, delete it
|
||||||
if ((pid = fork()) < 0)
|
if ((pid = fork()) < 0)
|
||||||
@ -758,18 +757,18 @@ static int lvm_clonepaths(struct bdev *orig, struct bdev *new, const char *oldna
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (strcmp(orig->type, "lvm")) {
|
if (strcmp(orig->type, "lvm")) {
|
||||||
|
const char *vg;
|
||||||
|
|
||||||
if (snap) {
|
if (snap) {
|
||||||
ERROR("LVM snapshot from %s backing store is not supported",
|
ERROR("LVM snapshot from %s backing store is not supported",
|
||||||
orig->type);
|
orig->type);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// Use VG 'lxc' by default
|
vg = default_lvm_vg();
|
||||||
// We will want to support custom VGs, at least as specified through
|
len = strlen("/dev/") + strlen(vg) + strlen(cname) + 2;
|
||||||
// /etc/lxc/lxc.conf, preferably also over cmdline
|
|
||||||
len = strlen("/dev/lxc/") + strlen(cname) + 1;
|
|
||||||
if ((new->src = malloc(len)) == NULL)
|
if ((new->src = malloc(len)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
ret = snprintf(new->src, len, "/dev/lxc/%s", cname);
|
ret = snprintf(new->src, len, "/dev/%s/%s", vg, cname);
|
||||||
if (ret < 0 || ret >= len)
|
if (ret < 0 || ret >= len)
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -137,7 +137,80 @@ static char *copypath(char *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *default_lxcpath;
|
char *default_lxcpath;
|
||||||
|
#define DEFAULT_VG "lxc"
|
||||||
|
char *default_lvmvg;
|
||||||
|
#define DEFAULT_ZFSROOT "lxc"
|
||||||
|
char *default_zfsroot;
|
||||||
|
|
||||||
|
const char *default_lvm_vg(void)
|
||||||
|
{
|
||||||
|
char buf[1024], *p;
|
||||||
|
FILE *fin;
|
||||||
|
|
||||||
|
if (default_lvmvg)
|
||||||
|
return default_lvmvg;
|
||||||
|
|
||||||
|
fin = fopen(LXC_GLOBAL_CONF, "r");
|
||||||
|
if (fin) {
|
||||||
|
while (fgets(buf, 1024, fin)) {
|
||||||
|
if (buf[0] == '#')
|
||||||
|
continue;
|
||||||
|
p = strstr(buf, "lvm_vg");
|
||||||
|
if (!p)
|
||||||
|
continue;
|
||||||
|
p = strchr(p, '=');
|
||||||
|
if (!p)
|
||||||
|
continue;
|
||||||
|
p++;
|
||||||
|
while (*p && (*p == ' ' || *p == '\t')) p++;
|
||||||
|
if (!*p)
|
||||||
|
continue;
|
||||||
|
default_lvmvg = copypath(p);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default_lvmvg = DEFAULT_VG;
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (fin)
|
||||||
|
fclose(fin);
|
||||||
|
return default_lvmvg;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *default_zfs_root(void)
|
||||||
|
{
|
||||||
|
char buf[1024], *p;
|
||||||
|
FILE *fin;
|
||||||
|
|
||||||
|
if (default_zfsroot)
|
||||||
|
return default_zfsroot;
|
||||||
|
|
||||||
|
fin = fopen(LXC_GLOBAL_CONF, "r");
|
||||||
|
if (fin) {
|
||||||
|
while (fgets(buf, 1024, fin)) {
|
||||||
|
if (buf[0] == '#')
|
||||||
|
continue;
|
||||||
|
p = strstr(buf, "zfsroot");
|
||||||
|
if (!p)
|
||||||
|
continue;
|
||||||
|
p = strchr(p, '=');
|
||||||
|
if (!p)
|
||||||
|
continue;
|
||||||
|
p++;
|
||||||
|
while (*p && (*p == ' ' || *p == '\t')) p++;
|
||||||
|
if (!*p)
|
||||||
|
continue;
|
||||||
|
default_zfsroot = copypath(p);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default_zfsroot = DEFAULT_ZFSROOT;
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (fin)
|
||||||
|
fclose(fin);
|
||||||
|
return default_zfsroot;
|
||||||
|
}
|
||||||
const char *default_lxc_path(void)
|
const char *default_lxc_path(void)
|
||||||
{
|
{
|
||||||
char buf[1024], *p;
|
char buf[1024], *p;
|
||||||
|
@ -31,6 +31,8 @@ extern int mkdir_p(const char *dir, mode_t mode);
|
|||||||
* path. Caller must free this buffer.
|
* path. Caller must free this buffer.
|
||||||
*/
|
*/
|
||||||
extern const char *default_lxc_path(void);
|
extern const char *default_lxc_path(void);
|
||||||
|
extern const char *default_zfs_root(void);
|
||||||
|
extern const char *default_lvm_vg(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BUILD_BUG_ON - break compile if a condition is true.
|
* BUILD_BUG_ON - break compile if a condition is true.
|
||||||
|
Loading…
Reference in New Issue
Block a user