]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/bdev.h
bdev: Add aufs support
[mirror_lxc.git] / src / lxc / bdev.h
CommitLineData
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:
1f92162d 27 * aufs, dir, raw, btrfs, overlayfs, aufs, lvm, loop, zfs
9be53773
SH
28 * someday: qemu-nbd, qcow2, qed
29 */
30
31#include "config.h"
d659597e 32#include <stdint.h>
948955a2 33#include <lxc/lxccontainer.h>
9be53773
SH
34
35struct bdev;
36
1897e3bc
SH
37/*
38 * specifications for how to create a new backing store
39 */
40struct bdev_specs {
72e99249 41 char *fstype;
d659597e 42 uint64_t fssize; // fs size in bytes
72e99249
SS
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;
1897e3bc
SH
51};
52
9be53773
SH
53struct 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);
60bf62d4 59 int (*destroy)(struct bdev *bdev);
1897e3bc
SH
60 int (*create)(struct bdev *bdev, const char *dest, const char *n,
61 struct bdev_specs *specs);
9be53773
SH
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,
d659597e 65 int snap, uint64_t newsize);
0a83cbbb 66 bool can_snapshot;
9be53773
SH
67};
68
ca52dcb5
SH
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 */
9be53773 76struct bdev {
74a3920a
AM
77 const struct bdev_ops *ops;
78 const char *type;
9be53773
SH
79 char *src;
80 char *dest;
a17b1e65 81 char *mntopts;
eddaaafd
SH
82 // turn the following into a union if need be
83 // lofd is the open fd for the mounted loopback file
84 int lofd;
9be53773
SH
85};
86
1f92162d 87char *overlay_getlower(char *p);
1897e3bc 88
8c39f7a4
SH
89bool bdev_is_dir(const char *path);
90
9be53773
SH
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 */
102struct bdev *bdev_init(const char *src, const char *dst, const char *data);
103
1354955b
SH
104struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
105 const char *lxcpath, const char *bdevtype,
d659597e 106 int flags, const char *bdevdata, uint64_t newsize,
dfb31b25 107 int *needs_rdep);
1897e3bc
SH
108struct bdev *bdev_create(const char *dest, const char *type,
109 const char *cname, struct bdev_specs *specs);
9be53773 110void bdev_put(struct bdev *bdev);
65fbbb0a
CS
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
9be53773 137#endif