]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/bdev.h
Move container creation fully into the api
[mirror_lxc.git] / src / lxc / bdev.h
1 #ifndef __LXC_BDEV_H
2 #define __LXC_BDEV_H
3 /* blockdev operations for:
4 * dir, raw, btrfs, overlayfs, aufs, lvm, loop, zfs, btrfs
5 * someday: qemu-nbd, qcow2, qed
6 */
7
8 #include "config.h"
9 #include "lxccontainer.h"
10
11 struct bdev;
12
13 /*
14 * specifications for how to create a new backing store
15 */
16 struct bdev_specs {
17 union {
18 struct {
19 char *zfsroot;
20 } zfs;
21 struct {
22 char *vg;
23 char *lv;
24 char *fstype;
25 unsigned long fssize; // fs size in bytes
26 } lvm;
27 } u;
28 };
29
30 struct bdev_ops {
31 /* detect whether path is of this bdev type */
32 int (*detect)(const char *path);
33 // mount requires src and dest to be set.
34 int (*mount)(struct bdev *bdev);
35 int (*umount)(struct bdev *bdev);
36 int (*destroy)(struct bdev *bdev);
37 int (*create)(struct bdev *bdev, const char *dest, const char *n,
38 struct bdev_specs *specs);
39 /* given original mount, rename the paths for cloned container */
40 int (*clone_paths)(struct bdev *orig, struct bdev *new, const char *oldname,
41 const char *cname, const char *oldpath, const char *lxcpath,
42 int snap, unsigned long newsize);
43 };
44
45 /*
46 * When lxc-start (conf.c) is mounting a rootfs, then src will be the
47 * 'lxc.rootfs' value, dest will be mount dir (i.e. $libdir/lxc) When clone
48 * or create is doing so, then dest will be $lxcpath/$lxcname/rootfs, since
49 * we may need to rsync from one to the other.
50 * data is so far unused.
51 */
52 struct bdev {
53 struct bdev_ops *ops;
54 char *type;
55 char *src;
56 char *dest;
57 char *data;
58 };
59
60 char *overlayfs_getlower(char *p);
61
62 /*
63 * Instantiate a bdev object. The src is used to determine which blockdev
64 * type this should be. The dst and data are optional, and will be used
65 * in case of mount/umount.
66 *
67 * Optionally, src can be 'dir:/var/lib/lxc/c1' or 'lvm:/dev/lxc/c1'. For
68 * other backing stores, this will allow additional options. In particular,
69 * "overlayfs:/var/lib/lxc/canonical/rootfs:/var/lib/lxc/c1/delta" will mean
70 * use /var/lib/lxc/canonical/rootfs as lower dir, and /var/lib/lxc/c1/delta
71 * as the upper, writeable layer.
72 */
73 struct bdev *bdev_init(const char *src, const char *dst, const char *data);
74
75 struct bdev *bdev_copy(const char *src, const char *oldname, const char *cname,
76 const char *oldpath, const char *lxcpath, const char *bdevtype,
77 int snap, const char *bdevdata, unsigned long newsize);
78 struct bdev *bdev_create(const char *dest, const char *type,
79 const char *cname, struct bdev_specs *specs);
80 void bdev_put(struct bdev *bdev);
81
82 /* define constants if the kernel/glibc headers don't define them */
83 #ifndef MS_DIRSYNC
84 #define MS_DIRSYNC 128
85 #endif
86
87 #ifndef MS_REC
88 #define MS_REC 16384
89 #endif
90
91 #ifndef MNT_DETACH
92 #define MNT_DETACH 2
93 #endif
94
95 #ifndef MS_SLAVE
96 #define MS_SLAVE (1<<19)
97 #endif
98
99 #ifndef MS_RELATIME
100 #define MS_RELATIME (1 << 21)
101 #endif
102
103 #ifndef MS_STRICTATIME
104 #define MS_STRICTATIME (1 << 24)
105 #endif
106
107 #endif