]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/storage/storage.h
storage: constify where possible
[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 "ext4"
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 /**
113 * storage_is_dir : Check whether the roots is a directory. This function will
114 * trust the config file. If the config file key
115 * lxc.rootfs.path is set to <storage type>:<container path>
116 * the confile parser will have split this into <storage type>
117 * and <container path> and set the <bdev_type> member in the
118 * lxc_rootfs struct to <storage type> and the <path> member
119 * will be set to a clean <container path> without the <storage
120 * type> prefix. This is the new, clean way of handling storage
121 * type specifications. If the <storage type> prefix is not
122 * detected liblxc will try to detect the storage type.
123 */
124 extern bool storage_is_dir(struct lxc_conf *conf);
125 extern bool storage_can_backup(struct lxc_conf *conf);
126
127 extern struct lxc_storage *storage_init(struct lxc_conf *conf);
128
129 extern struct lxc_storage *storage_copy(struct lxc_container *c,
130 const char *cname, const char *lxcpath,
131 const char *bdevtype, int flags,
132 const char *bdevdata, uint64_t newsize,
133 bool *needs_rdep);
134 extern struct lxc_storage *storage_create(const char *dest, const char *type,
135 const char *cname,
136 struct bdev_specs *specs);
137 extern void storage_put(struct lxc_storage *bdev);
138 extern bool storage_destroy(struct lxc_conf *conf);
139 extern bool rootfs_is_blockdev(struct lxc_conf *conf);
140 extern const char *lxc_storage_get_path(char *src, const char *prefix);
141
142 #endif /* #define __LXC_STORAGE_H */