]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/bdev.h
bdev: Add aufs support
[mirror_lxc.git] / src / lxc / bdev.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef __LXC_BDEV_H
25 #define __LXC_BDEV_H
26 /* blockdev operations for:
27 * aufs, dir, raw, btrfs, overlayfs, aufs, lvm, loop, zfs
28 * someday: qemu-nbd, qcow2, qed
29 */
30
31 #include "config.h"
32 #include <stdint.h>
33 #include <lxc/lxccontainer.h>
34
35 struct bdev;
36
37 /*
38 * specifications for how to create a new backing store
39 */
40 struct bdev_specs {
41 char *fstype;
42 uint64_t fssize; // fs size in bytes
43 struct {
44 char *zfsroot;
45 } zfs;
46 struct {
47 char *vg;
48 char *lv;
49 char *thinpool; // lvm thin pool to use, if any
50 } lvm;
51 };
52
53 struct bdev_ops {
54 /* detect whether path is of this bdev type */
55 int (*detect)(const char *path);
56 // mount requires src and dest to be set.
57 int (*mount)(struct bdev *bdev);
58 int (*umount)(struct bdev *bdev);
59 int (*destroy)(struct bdev *bdev);
60 int (*create)(struct bdev *bdev, const char *dest, const char *n,
61 struct bdev_specs *specs);
62 /* given original mount, rename the paths for cloned container */
63 int (*clone_paths)(struct bdev *orig, struct bdev *new, const char *oldname,
64 const char *cname, const char *oldpath, const char *lxcpath,
65 int snap, uint64_t newsize);
66 bool can_snapshot;
67 };
68
69 /*
70 * When lxc-start (conf.c) is mounting a rootfs, then src will be the
71 * 'lxc.rootfs' value, dest will be mount dir (i.e. $libdir/lxc) When clone
72 * or create is doing so, then dest will be $lxcpath/$lxcname/rootfs, since
73 * we may need to rsync from one to the other.
74 * data is so far unused.
75 */
76 struct bdev {
77 const struct bdev_ops *ops;
78 const char *type;
79 char *src;
80 char *dest;
81 char *mntopts;
82 // turn the following into a union if need be
83 // lofd is the open fd for the mounted loopback file
84 int lofd;
85 };
86
87 char *overlay_getlower(char *p);
88
89 bool bdev_is_dir(const char *path);
90
91 /*
92 * Instantiate a bdev object. The src is used to determine which blockdev
93 * type this should be. The dst and data are optional, and will be used
94 * in case of mount/umount.
95 *
96 * Optionally, src can be 'dir:/var/lib/lxc/c1' or 'lvm:/dev/lxc/c1'. For
97 * other backing stores, this will allow additional options. In particular,
98 * "overlayfs:/var/lib/lxc/canonical/rootfs:/var/lib/lxc/c1/delta" will mean
99 * use /var/lib/lxc/canonical/rootfs as lower dir, and /var/lib/lxc/c1/delta
100 * as the upper, writeable layer.
101 */
102 struct bdev *bdev_init(const char *src, const char *dst, const char *data);
103
104 struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
105 const char *lxcpath, const char *bdevtype,
106 int flags, const char *bdevdata, uint64_t newsize,
107 int *needs_rdep);
108 struct bdev *bdev_create(const char *dest, const char *type,
109 const char *cname, struct bdev_specs *specs);
110 void bdev_put(struct bdev *bdev);
111
112 /* define constants if the kernel/glibc headers don't define them */
113 #ifndef MS_DIRSYNC
114 #define MS_DIRSYNC 128
115 #endif
116
117 #ifndef MS_REC
118 #define MS_REC 16384
119 #endif
120
121 #ifndef MNT_DETACH
122 #define MNT_DETACH 2
123 #endif
124
125 #ifndef MS_SLAVE
126 #define MS_SLAVE (1<<19)
127 #endif
128
129 #ifndef MS_RELATIME
130 #define MS_RELATIME (1 << 21)
131 #endif
132
133 #ifndef MS_STRICTATIME
134 #define MS_STRICTATIME (1 << 24)
135 #endif
136
137 #endif