Skip to content

Commit

Permalink
OpenZFS restructuring - libzfs
Browse files Browse the repository at this point in the history
Factor Linux specific functionality out of libzfs.

Reviewed-by: Allan Jude <[email protected]>
Reviewed-by: Jorgen Lundman <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Matthew Macy <[email protected]>
Closes #9377
  • Loading branch information
mattmacy authored and behlendorf committed Oct 3, 2019
1 parent 7c5eff9 commit 73cdcc6
Show file tree
Hide file tree
Showing 11 changed files with 1,026 additions and 797 deletions.
46 changes: 46 additions & 0 deletions include/libzfs_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,52 @@ extern int zfs_parse_options(char *, zfs_share_proto_t);
extern int zfs_unshare_proto(zfs_handle_t *,
const char *, zfs_share_proto_t *);

typedef struct {
zfs_prop_t p_prop;
char *p_name;
int p_share_err;
int p_unshare_err;
} proto_table_t;

typedef struct differ_info {
zfs_handle_t *zhp;
char *fromsnap;
char *frommnt;
char *tosnap;
char *tomnt;
char *ds;
char *dsmnt;
char *tmpsnap;
char errbuf[1024];
boolean_t isclone;
boolean_t scripted;
boolean_t classify;
boolean_t timestamped;
uint64_t shares;
int zerr;
int cleanupfd;
int outputfd;
int datafd;
} differ_info_t;

extern proto_table_t proto_table[PROTO_END];

extern int do_mount(const char *src, const char *mntpt, char *opts, int flags);
extern int do_unmount(const char *mntpt, int flags);
extern int zfs_can_user_mount(void);
extern int zfs_share_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto);
extern int unshare_one(libzfs_handle_t *hdl, const char *name,
const char *mountpoint, zfs_share_proto_t proto);
extern boolean_t zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t buflen,
zprop_source_t *source, int flags);
extern zfs_share_type_t is_shared_impl(libzfs_handle_t *hdl,
const char *mountpoint, zfs_share_proto_t proto);
extern int libzfs_load_module(void);
extern int zpool_relabel_disk(libzfs_handle_t *hdl, const char *path,
const char *msg);
extern int find_shares_object(differ_info_t *di);
extern void libzfs_set_pipe_max(int infd);

#ifdef __cplusplus
}
#endif
Expand Down
18 changes: 16 additions & 2 deletions lib/libzfs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ USER_C = \
libzfs_status.c \
libzfs_util.c

if BUILD_LINUX
USER_C += \
os/linux/libzfs_mount_os.c \
os/linux/libzfs_pool_os.c \
os/linux/libzfs_sendrecv_os.c \
os/linux/libzfs_util_os.c
endif


KERNEL_C = \
algs/sha2/sha2.c \
zfeature_common.c \
Expand All @@ -51,14 +60,19 @@ nodist_libzfs_la_SOURCES = \

libzfs_la_LIBADD = \
$(top_builddir)/lib/libnvpair/libnvpair.la \
$(top_builddir)/lib/libshare/libshare.la \
$(top_builddir)/lib/libuutil/libuutil.la \
$(top_builddir)/lib/libzfs_core/libzfs_core.la \
$(top_builddir)/lib/libzutil/libzutil.la

libzfs_la_LIBADD += -lm $(LIBSSL)
if BUILD_LINUX
libzfs_la_LIBADD += \
$(top_builddir)/lib/libshare/libshare.la
endif

libzfs_la_LDFLAGS = -version-info 2:0:0

libzfs_la_LIBADD += -lm $(LIBSSL)

EXTRA_DIST = $(libzfs_pc_DATA) $(USER_C)

# Licensing data
Expand Down
42 changes: 1 addition & 41 deletions lib/libzfs/libzfs_diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,13 @@
#include "libzfs_impl.h"

#define ZDIFF_SNAPDIR "/.zfs/snapshot/"
#define ZDIFF_SHARESDIR "/.zfs/shares/"
#define ZDIFF_PREFIX "zfs-diff-%d"

#define ZDIFF_ADDED '+'
#define ZDIFF_MODIFIED 'M'
#define ZDIFF_REMOVED '-'
#define ZDIFF_RENAMED 'R'

typedef struct differ_info {
zfs_handle_t *zhp;
char *fromsnap;
char *frommnt;
char *tosnap;
char *tomnt;
char *ds;
char *dsmnt;
char *tmpsnap;
char errbuf[1024];
boolean_t isclone;
boolean_t scripted;
boolean_t classify;
boolean_t timestamped;
uint64_t shares;
int zerr;
int cleanupfd;
int outputfd;
int datafd;
} differ_info_t;

/*
* Given a {dsname, object id}, get the object path
Expand Down Expand Up @@ -487,25 +466,6 @@ differ(void *arg)
return ((void *)0);
}

static int
find_shares_object(differ_info_t *di)
{
char fullpath[MAXPATHLEN];
struct stat64 sb = { 0 };

(void) strlcpy(fullpath, di->dsmnt, MAXPATHLEN);
(void) strlcat(fullpath, ZDIFF_SHARESDIR, MAXPATHLEN);

if (stat64(fullpath, &sb) != 0) {
(void) snprintf(di->errbuf, sizeof (di->errbuf),
dgettext(TEXT_DOMAIN, "Cannot stat %s"), fullpath);
return (zfs_error(di->zhp->zfs_hdl, EZFS_DIFF, di->errbuf));
}

di->shares = (uint64_t)sb.st_ino;
return (0);
}

static int
make_temp_snapshot(differ_info_t *di)
{
Expand Down Expand Up @@ -737,7 +697,7 @@ setup_differ_info(zfs_handle_t *zhp, const char *fromsnap,
{
di->zhp = zhp;

di->cleanupfd = open(ZFS_DEV, O_RDWR);
di->cleanupfd = open(ZFS_DEV, O_RDWR|O_EXCL);
VERIFY(di->cleanupfd >= 0);

if (get_snapshot_names(di, fromsnap, tosnap) != 0)
Expand Down
Loading

0 comments on commit 73cdcc6

Please sign in to comment.