]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/storage/storage.h
Merge pull request #1801 from brauner/2017-09-09/userns_exec
[mirror_lxc.git] / src / lxc / storage / storage.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_STORAGE_H
25 #define __LXC_STORAGE_H
26
27 #include "config.h"
28 #include <stdint.h>
29 #include <sys/mount.h>
30
31 #include <lxc/lxccontainer.h>
32
33 #if IS_BIONIC
34 #include <../include/lxcmntent.h>
35 #else
36 #include <mntent.h>
37 #endif
38
39 #ifndef MS_DIRSYNC
40 #define MS_DIRSYNC 128
41 #endif
42
43 #ifndef MS_REC
44 #define MS_REC 16384
45 #endif
46
47 #ifndef MNT_DETACH
48 #define MNT_DETACH 2
49 #endif
50
51 #ifndef MS_SLAVE
52 #define MS_SLAVE (1 << 19)
53 #endif
54
55 #ifndef MS_RELATIME
56 #define MS_RELATIME (1 << 21)
57 #endif
58
59 #ifndef MS_STRICTATIME
60 #define MS_STRICTATIME (1 << 24)
61 #endif
62
63 #define DEFAULT_FS_SIZE 1073741824
64 #define DEFAULT_FSTYPE "ext3"
65
66 #define LXC_STORAGE_INTERNAL_OVERLAY_RESTORE (1 << 6)
67
68 struct lxc_storage;
69
70 struct lxc_storage_ops {
71 /* detect whether path is of this bdev type */
72 bool (*detect)(const char *path);
73
74 /* mount requires src and dest to be set. */
75 int (*mount)(struct lxc_storage *bdev);
76 int (*umount)(struct lxc_storage *bdev);
77 int (*destroy)(struct lxc_storage *bdev);
78 int (*create)(struct lxc_storage *bdev, const char *dest, const char *n,
79 struct bdev_specs *specs);
80 /* given original mount, rename the paths for cloned container */
81 int (*clone_paths)(struct lxc_storage *orig, struct lxc_storage *new,
82 const char *oldname, const char *cname,
83 const char *oldpath, const char *lxcpath, int snap,
84 uint64_t newsize, struct lxc_conf *conf);
85 bool (*copy)(struct lxc_conf *conf, struct lxc_storage *orig,
86 struct lxc_storage *new, uint64_t newsize);
87 bool (*snapshot)(struct lxc_conf *conf, struct lxc_storage *orig,
88 struct lxc_storage *new, uint64_t newsize);
89 bool can_snapshot;
90 bool can_backup;
91 };
92
93 /* When lxc is mounting a rootfs, then src will be the "lxc.rootfs.path" value,
94 * dest will be the mount dir (i.e. "<libdir>/lxc") When clone or create is
95 * doing so, then dest will be "<lxcpath>/<lxcname>/rootfs", since we may need
96 * to rsync from one to the other.
97 */
98 struct lxc_storage {
99 const struct lxc_storage_ops *ops;
100 const char *type;
101 char *src;
102 char *dest;
103 char *mntopts;
104 /* Turn the following into a union if need be. */
105 /* lofd is the open fd for the mounted loopback file. */
106 int lofd;
107 /* index for the connected nbd device. */
108 int nbd_idx;
109 int flags;
110 };
111
112 extern bool storage_is_dir(struct lxc_conf *conf, const char *path);
113 extern bool storage_can_backup(struct lxc_conf *conf);
114
115 /* Instantiate a lxc_storage object. The src is used to determine which blockdev
116 * type this should be. The dst and data are optional, and will be used in case
117 * of mount/umount.
118 *
119 * The source will be "dir:/var/lib/lxc/c1" or "lvm:/dev/lxc/c1". For other
120 * backing stores, this will allow additional options. In particular,
121 * "overlayfs:/var/lib/lxc/canonical/rootfs:/var/lib/lxc/c1/delta" will mean use
122 * /var/lib/lxc/canonical/rootfs as lower dir, and /var/lib/lxc/c1/delta as the
123 * upper, writeable layer.
124 */
125 extern struct lxc_storage *storage_init(struct lxc_conf *conf, const char *src,
126 const char *dst, const char *data);
127
128 extern struct lxc_storage *storage_copy(struct lxc_container *c0,
129 const char *cname, const char *lxcpath,
130 const char *bdevtype, int flags,
131 const char *bdevdata, uint64_t newsize,
132 bool *needs_rdep);
133 extern struct lxc_storage *storage_create(const char *dest, const char *type,
134 const char *cname,
135 struct bdev_specs *specs);
136 extern void storage_put(struct lxc_storage *bdev);
137 extern bool storage_destroy(struct lxc_conf *conf);
138
139 extern int storage_destroy_wrapper(void *data);
140 extern bool rootfs_is_blockdev(struct lxc_conf *conf);
141 extern char *lxc_storage_get_path(char *src, const char *prefix);
142
143 #endif /* #define __LXC_STORAGE_H */