Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / os / fs / ZFS.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #define HAVE_IOCTL_IN_SYS_IOCTL_H
5 #include <libzfs.h>
6 #include "ZFS.h"
7
8 const int ZFS::TYPE_FILESYSTEM  = ZFS_TYPE_FILESYSTEM;
9 const int ZFS::TYPE_SNAPSHOT    = ZFS_TYPE_SNAPSHOT;
10 const int ZFS::TYPE_VOLUME      = ZFS_TYPE_VOLUME;
11 const int ZFS::TYPE_DATASET     = ZFS_TYPE_DATASET;
12
13 ZFS::~ZFS()
14 {
15   if (g_zfs)
16     ::libzfs_fini((libzfs_handle_t*)g_zfs);
17 }
18
19 int ZFS::init()
20 {
21   g_zfs = ::libzfs_init();
22   return g_zfs ? 0 : -EINVAL;
23 }
24
25 ZFS::Handle *ZFS::open(const char *n, int t)
26 {
27   return (ZFS::Handle*)::zfs_open((libzfs_handle_t*)g_zfs, n, (zfs_type_t)t);
28 }
29
30 void ZFS::close(ZFS::Handle *h)
31 {
32   ::zfs_close((zfs_handle_t*)h);
33 }
34
35 const char *ZFS::get_name(ZFS::Handle *h)
36 {
37   return ::zfs_get_name((zfs_handle_t*)h);
38 }
39
40 ZFS::Handle *ZFS::path_to_zhandle(const char *p, int t)
41 {
42   return ::zfs_path_to_zhandle((libzfs_handle_t*)g_zfs, (char *)p, (zfs_type_t)t);
43 }
44
45 int ZFS::create(const char *n, int t)
46 {
47   return ::zfs_create((libzfs_handle_t*)g_zfs, n, (zfs_type_t)t, NULL);
48 }
49
50 int ZFS::snapshot(const char *n, bool r)
51 {
52   return ::zfs_snapshot((libzfs_handle_t*)g_zfs, n, (boolean_t)r, NULL);
53 }
54
55 int ZFS::rollback(ZFS::Handle *h, ZFS::Handle *snap, bool f)
56 {
57   return ::zfs_rollback((zfs_handle_t*)h, (zfs_handle_t*)snap, (boolean_t)f);
58 }
59
60 int ZFS::destroy_snaps(ZFS::Handle *h, const char *n, bool d)
61 {
62   return ::zfs_destroy_snaps((zfs_handle_t*)h, (char *)n, (boolean_t)d);
63 }
64
65 bool ZFS::is_mounted(ZFS::Handle *h, char **p)
66 {
67   return (bool)::zfs_is_mounted((zfs_handle_t*)h, p);
68 }
69
70 int ZFS::mount(ZFS::Handle *h, const char *o, int f)
71 {
72   return ::zfs_mount((zfs_handle_t*)h, o, f);
73 }
74
75 int ZFS::umount(ZFS::Handle *h, const char *o, int f)
76 {
77   return ::zfs_unmount((zfs_handle_t*)h, o, f);
78 }
79
80 int ZFS::iter_snapshots_sorted(ZFS::Handle *h, ZFS::iter_func f, void *d)
81 {
82   return ::zfs_iter_snapshots_sorted((zfs_handle_t*)h, (zfs_iter_f)f, d);
83 }