]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/storage/storage.h
Merge pull request #2643 from brauner/2018-09-23/cgroup_scoping_fixes
[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 <stdint.h>
28 #include <sys/mount.h>
29
30 #include <lxc/lxccontainer.h>
31
32 #if IS_BIONIC
33 #include <../include/lxcmntent.h>
34 #else
35 #include <mntent.h>
36 #endif
37
38 #ifndef MS_DIRSYNC
39 #define MS_DIRSYNC 128
40 #endif
41
42 #ifndef MS_REC
43 #define MS_REC 16384
44 #endif
45
46 #ifndef MNT_DETACH
47 #define MNT_DETACH 2
48 #endif
49
50 #ifndef MS_SLAVE
51 #define MS_SLAVE (1 << 19)
52 #endif
53
54 #ifndef MS_RELATIME
55 #define MS_RELATIME (1 << 21)
56 #endif
57
58 #ifndef MS_STRICTATIME
59 #define MS_STRICTATIME (1 << 24)
60 #endif
61
62 #define DEFAULT_FS_SIZE 1073741824
63 #define DEFAULT_FSTYPE "ext4"
64
65 #define LXC_STORAGE_INTERNAL_OVERLAY_RESTORE (1 << 6)
66
67 struct lxc_storage;
68
69 struct lxc_storage_ops {
70 /* detect whether path is of this bdev type */
71 bool (*detect)(const char *path);
72
73 /* mount requires src and dest to be set. */
74 int (*mount)(struct lxc_storage *bdev);
75 int (*umount)(struct lxc_storage *bdev);
76 int (*destroy)(struct lxc_storage *bdev);
77 int (*create)(struct lxc_storage *bdev, const char *dest, const char *n,
78 struct bdev_specs *specs);
79 /* given original mount, rename the paths for cloned container */
80 int (*clone_paths)(struct lxc_storage *orig, struct lxc_storage *new,
81 const char *oldname, const char *cname,
82 const char *oldpath, const char *lxcpath, int snap,
83 uint64_t newsize, struct lxc_conf *conf);
84 bool (*copy)(struct lxc_conf *conf, struct lxc_storage *orig,
85 struct lxc_storage *new, uint64_t newsize);
86 bool (*snapshot)(struct lxc_conf *conf, struct lxc_storage *orig,
87 struct lxc_storage *new, uint64_t newsize);
88 bool can_snapshot;
89 bool can_backup;
90 };
91
92 /* When lxc is mounting a rootfs, then src will be the "lxc.rootfs.path" value,
93 * dest will be the mount dir (i.e. "<libdir>/lxc") When clone or create is
94 * doing so, then dest will be "<lxcpath>/<lxcname>/rootfs", since we may need
95 * to rsync from one to the other.
96 */
97 struct lxc_storage {
98 const struct lxc_storage_ops *ops;
99 const char *type;
100 char *src;
101 char *dest;
102 char *mntopts;
103 /* Turn the following into a union if need be. */
104 /* lofd is the open fd for the mounted loopback file. */
105 int lofd;
106 /* index for the connected nbd device. */
107 int nbd_idx;
108 int flags;
109 };
110
111 /**
112 * storage_is_dir : Check whether the roots is a directory. This function will
113 * trust the config file. If the config file key
114 * lxc.rootfs.path is set to <storage type>:<container path>
115 * the confile parser will have split this into <storage type>
116 * and <container path> and set the <bdev_type> member in the
117 * lxc_rootfs struct to <storage type> and the <path> member
118 * will be set to a clean <container path> without the <storage
119 * type> prefix. This is the new, clean way of handling storage
120 * type specifications. If the <storage type> prefix is not
121 * detected liblxc will try to detect the storage type.
122 */
123 extern bool storage_is_dir(struct lxc_conf *conf);
124 extern bool storage_can_backup(struct lxc_conf *conf);
125
126 extern struct lxc_storage *storage_init(struct lxc_conf *conf);
127
128 extern struct lxc_storage *storage_copy(struct lxc_container *c,
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 extern bool rootfs_is_blockdev(struct lxc_conf *conf);
139 extern const char *lxc_storage_get_path(char *src, const char *prefix);
140
141 #endif /* #define __LXC_STORAGE_H */