]>
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: | |
3155e7f9 | 27 | * dir, raw, btrfs, overlayfs, aufs, lvm, loop, zfs |
9be53773 SH |
28 | * someday: qemu-nbd, qcow2, qed |
29 | */ | |
30 | ||
31 | #include "config.h" | |
32 | #include "lxccontainer.h" | |
33 | ||
34 | struct bdev; | |
35 | ||
1897e3bc SH |
36 | /* |
37 | * specifications for how to create a new backing store | |
38 | */ | |
39 | struct bdev_specs { | |
40 | union { | |
41 | struct { | |
42 | char *zfsroot; | |
43 | } zfs; | |
44 | struct { | |
45 | char *vg; | |
46 | char *lv; | |
47 | char *fstype; | |
48 | unsigned long fssize; // fs size in bytes | |
49 | } lvm; | |
eddaaafd SH |
50 | struct { |
51 | char *fstype; | |
52 | unsigned long fssize; // fs size in bytes | |
53 | } loop; | |
1897e3bc SH |
54 | } u; |
55 | }; | |
56 | ||
9be53773 SH |
57 | struct bdev_ops { |
58 | /* detect whether path is of this bdev type */ | |
59 | int (*detect)(const char *path); | |
60 | // mount requires src and dest to be set. | |
61 | int (*mount)(struct bdev *bdev); | |
62 | int (*umount)(struct bdev *bdev); | |
60bf62d4 | 63 | int (*destroy)(struct bdev *bdev); |
1897e3bc SH |
64 | int (*create)(struct bdev *bdev, const char *dest, const char *n, |
65 | struct bdev_specs *specs); | |
9be53773 SH |
66 | /* given original mount, rename the paths for cloned container */ |
67 | int (*clone_paths)(struct bdev *orig, struct bdev *new, const char *oldname, | |
68 | const char *cname, const char *oldpath, const char *lxcpath, | |
69 | int snap, unsigned long newsize); | |
70 | }; | |
71 | ||
ca52dcb5 SH |
72 | /* |
73 | * When lxc-start (conf.c) is mounting a rootfs, then src will be the | |
74 | * 'lxc.rootfs' value, dest will be mount dir (i.e. $libdir/lxc) When clone | |
75 | * or create is doing so, then dest will be $lxcpath/$lxcname/rootfs, since | |
76 | * we may need to rsync from one to the other. | |
77 | * data is so far unused. | |
78 | */ | |
9be53773 SH |
79 | struct bdev { |
80 | struct bdev_ops *ops; | |
81 | char *type; | |
82 | char *src; | |
83 | char *dest; | |
84 | char *data; | |
eddaaafd SH |
85 | // turn the following into a union if need be |
86 | // lofd is the open fd for the mounted loopback file | |
87 | int lofd; | |
9be53773 SH |
88 | }; |
89 | ||
1897e3bc SH |
90 | char *overlayfs_getlower(char *p); |
91 | ||
9be53773 SH |
92 | /* |
93 | * Instantiate a bdev object. The src is used to determine which blockdev | |
94 | * type this should be. The dst and data are optional, and will be used | |
95 | * in case of mount/umount. | |
96 | * | |
97 | * Optionally, src can be 'dir:/var/lib/lxc/c1' or 'lvm:/dev/lxc/c1'. For | |
98 | * other backing stores, this will allow additional options. In particular, | |
99 | * "overlayfs:/var/lib/lxc/canonical/rootfs:/var/lib/lxc/c1/delta" will mean | |
100 | * use /var/lib/lxc/canonical/rootfs as lower dir, and /var/lib/lxc/c1/delta | |
101 | * as the upper, writeable layer. | |
102 | */ | |
103 | struct bdev *bdev_init(const char *src, const char *dst, const char *data); | |
104 | ||
105 | struct bdev *bdev_copy(const char *src, const char *oldname, const char *cname, | |
106 | const char *oldpath, const char *lxcpath, const char *bdevtype, | |
dfb31b25 SH |
107 | int snap, const char *bdevdata, unsigned long newsize, |
108 | int *needs_rdep); | |
1897e3bc SH |
109 | struct bdev *bdev_create(const char *dest, const char *type, |
110 | const char *cname, struct bdev_specs *specs); | |
9be53773 | 111 | void bdev_put(struct bdev *bdev); |
65fbbb0a CS |
112 | |
113 | /* define constants if the kernel/glibc headers don't define them */ | |
114 | #ifndef MS_DIRSYNC | |
115 | #define MS_DIRSYNC 128 | |
116 | #endif | |
117 | ||
118 | #ifndef MS_REC | |
119 | #define MS_REC 16384 | |
120 | #endif | |
121 | ||
122 | #ifndef MNT_DETACH | |
123 | #define MNT_DETACH 2 | |
124 | #endif | |
125 | ||
126 | #ifndef MS_SLAVE | |
127 | #define MS_SLAVE (1<<19) | |
128 | #endif | |
129 | ||
130 | #ifndef MS_RELATIME | |
131 | #define MS_RELATIME (1 << 21) | |
132 | #endif | |
133 | ||
134 | #ifndef MS_STRICTATIME | |
135 | #define MS_STRICTATIME (1 << 24) | |
136 | #endif | |
137 | ||
9be53773 | 138 | #endif |