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