]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/bdev.h
pivot_root: switch to a new mechanism (v2)
[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, nbd (qcow2, raw, vdi, qed)
28 */
29
30 #include "config.h"
31 #include <stdint.h>
32 #include <lxc/lxccontainer.h>
33
34 struct bdev;
35
36 struct bdev_ops {
37 /* detect whether path is of this bdev type */
38 int (*detect)(const char *path);
39 // mount requires src and dest to be set.
40 int (*mount)(struct bdev *bdev);
41 int (*umount)(struct bdev *bdev);
42 int (*destroy)(struct bdev *bdev);
43 int (*create)(struct bdev *bdev, const char *dest, const char *n,
44 struct bdev_specs *specs);
45 /* given original mount, rename the paths for cloned container */
46 int (*clone_paths)(struct bdev *orig, struct bdev *new, const char *oldname,
47 const char *cname, const char *oldpath, const char *lxcpath,
48 int snap, uint64_t newsize, struct lxc_conf *conf);
49 bool can_snapshot;
50 bool can_backup;
51 };
52
53 /*
54 * When lxc-start (conf.c) is mounting a rootfs, then src will be the
55 * 'lxc.rootfs' value, dest will be mount dir (i.e. $libdir/lxc) When clone
56 * or create is doing so, then dest will be $lxcpath/$lxcname/rootfs, since
57 * we may need to rsync from one to the other.
58 * data is so far unused.
59 */
60 struct bdev {
61 const struct bdev_ops *ops;
62 const char *type;
63 char *src;
64 char *dest;
65 char *mntopts;
66 // turn the following into a union if need be
67 // lofd is the open fd for the mounted loopback file
68 int lofd;
69 // index for the connected nbd device
70 int nbd_idx;
71 };
72
73 char *overlay_getlower(char *p);
74
75 bool bdev_is_dir(struct lxc_conf *conf, const char *path);
76 bool bdev_can_backup(struct lxc_conf *conf);
77
78 /*
79 * Instantiate a bdev object. The src is used to determine which blockdev
80 * type this should be. The dst and data are optional, and will be used
81 * in case of mount/umount.
82 *
83 * Optionally, src can be 'dir:/var/lib/lxc/c1' or 'lvm:/dev/lxc/c1'. For
84 * other backing stores, this will allow additional options. In particular,
85 * "overlayfs:/var/lib/lxc/canonical/rootfs:/var/lib/lxc/c1/delta" will mean
86 * use /var/lib/lxc/canonical/rootfs as lower dir, and /var/lib/lxc/c1/delta
87 * as the upper, writeable layer.
88 */
89 struct bdev *bdev_init(struct lxc_conf *conf, const char *src, const char *dst,
90 const char *data);
91
92 struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
93 const char *lxcpath, const char *bdevtype,
94 int flags, const char *bdevdata, uint64_t newsize,
95 int *needs_rdep);
96 struct bdev *bdev_create(const char *dest, const char *type,
97 const char *cname, struct bdev_specs *specs);
98 void bdev_put(struct bdev *bdev);
99
100 /*
101 * these are really for qemu-nbd support, as container shutdown
102 * must explicitly request device detach.
103 */
104 bool attach_block_device(struct lxc_conf *conf);
105 void detach_block_device(struct lxc_conf *conf);
106
107 bool rootfs_is_blockdev(struct lxc_conf *conf);
108
109 /* define constants if the kernel/glibc headers don't define them */
110 #ifndef MS_DIRSYNC
111 #define MS_DIRSYNC 128
112 #endif
113
114 #ifndef MS_REC
115 #define MS_REC 16384
116 #endif
117
118 #ifndef MNT_DETACH
119 #define MNT_DETACH 2
120 #endif
121
122 #ifndef MS_SLAVE
123 #define MS_SLAVE (1<<19)
124 #endif
125
126 #ifndef MS_RELATIME
127 #define MS_RELATIME (1 << 21)
128 #endif
129
130 #ifndef MS_STRICTATIME
131 #define MS_STRICTATIME (1 << 24)
132 #endif
133
134 #endif