]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/storage/storage.h
storage: use userns_exec_full()
[mirror_lxc.git] / src / lxc / storage / storage.h
CommitLineData
250b1eec
SG
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
28d832c4
CB
24#ifndef __LXC_STORAGE_H
25#define __LXC_STORAGE_H
9be53773 26
493de765 27#include "config.h"
3c16d0cb 28#include <stdint.h>
212bc241 29#include <sys/mount.h>
9be53773 30
493de765 31#include <lxc/lxccontainer.h>
c2af52cf 32
02078686
CB
33#if IS_BIONIC
34#include <../include/lxcmntent.h>
35#else
36#include <mntent.h>
37#endif
38
c2af52cf 39#ifndef MS_DIRSYNC
212bc241 40#define MS_DIRSYNC 128
c2af52cf
SG
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
eab15c1e 52#define MS_SLAVE (1 << 19)
c2af52cf
SG
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
2b9cbd53
CB
63#define DEFAULT_FS_SIZE 1073741824
64#define DEFAULT_FSTYPE "ext3"
65
17a367d8
CB
66#define LXC_STORAGE_INTERNAL_OVERLAY_RESTORE (1 << 6)
67
10bc1861 68struct lxc_storage;
9be53773 69
10bc1861 70struct lxc_storage_ops {
9be53773 71 /* detect whether path is of this bdev type */
3d2ae1e2 72 bool (*detect)(const char *path);
1a0e70ac
CB
73
74 /* mount requires src and dest to be set. */
10bc1861
CB
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,
493de765 79 struct bdev_specs *specs);
9be53773 80 /* given original mount, rename the paths for cloned container */
10bc1861 81 int (*clone_paths)(struct lxc_storage *orig, struct lxc_storage *new,
493de765
CB
82 const char *oldname, const char *cname,
83 const char *oldpath, const char *lxcpath, int snap,
84 uint64_t newsize, struct lxc_conf *conf);
10bc1861
CB
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);
0a83cbbb 89 bool can_snapshot;
cdd01be2 90 bool can_backup;
9be53773
SH
91};
92
10bc1861
CB
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.
ca52dcb5 97 */
10bc1861
CB
98struct lxc_storage {
99 const struct lxc_storage_ops *ops;
74a3920a 100 const char *type;
9be53773
SH
101 char *src;
102 char *dest;
a17b1e65 103 char *mntopts;
493de765
CB
104 /* Turn the following into a union if need be. */
105 /* lofd is the open fd for the mounted loopback file. */
eddaaafd 106 int lofd;
493de765 107 /* index for the connected nbd device. */
76a26f55 108 int nbd_idx;
17a367d8 109 int flags;
9be53773
SH
110};
111
10bc1861
CB
112extern bool storage_is_dir(struct lxc_conf *conf, const char *path);
113extern bool storage_can_backup(struct lxc_conf *conf);
8c39f7a4 114
10bc1861
CB
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.
9be53773 118 *
10bc1861
CB
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.
9be53773 124 */
10bc1861
CB
125extern struct lxc_storage *storage_init(struct lxc_conf *conf, const char *src,
126 const char *dst, const char *data);
127
128extern 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,
07db51a2 132 bool *needs_rdep);
10bc1861
CB
133extern struct lxc_storage *storage_create(const char *dest, const char *type,
134 const char *cname,
135 struct bdev_specs *specs);
136extern void storage_put(struct lxc_storage *bdev);
137extern bool storage_destroy(struct lxc_conf *conf);
493de765 138
10bc1861 139extern int storage_destroy_wrapper(void *data);
f2d5a09d 140extern bool rootfs_is_blockdev(struct lxc_conf *conf);
4f25fd38 141extern char *lxc_storage_get_path(char *src, const char *prefix);
bfd77214 142
28d832c4 143#endif /* #define __LXC_STORAGE_H */