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