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