Skip to content

Commit

Permalink
libzfs: add zfs_get_underlying_type. Stop including libzfs_impl.h in cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
  • Loading branch information
nabijaczleweli committed May 25, 2021
1 parent b02aa38 commit 222d2be
Show file tree
Hide file tree
Showing 6 changed files with 660 additions and 639 deletions.
5 changes: 3 additions & 2 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
#include <sys/types.h>
#include <time.h>
#include <sys/zfs_project.h>
#include <sys/spa.h>
#include <sys/zio.h>

#include <libzfs.h>
#include <libzfs_core.h>
Expand All @@ -78,7 +80,6 @@
#include "zfs_iter.h"
#include "zfs_util.h"
#include "zfs_comutil.h"
#include "libzfs_impl.h"
#include "zfs_projectutil.h"

libzfs_handle_t *g_zfs;
Expand Down Expand Up @@ -3315,7 +3316,7 @@ zfs_do_userspace(int argc, char **argv)
if ((zhp = zfs_path_to_zhandle(g_zfs, argv[0], ZFS_TYPE_FILESYSTEM |
ZFS_TYPE_SNAPSHOT)) == NULL)
return (1);
if (zhp->zfs_head_type != ZFS_TYPE_FILESYSTEM) {
if (zfs_get_underlying_type(zhp) != ZFS_TYPE_FILESYSTEM) {
(void) fprintf(stderr, gettext("operation is only applicable "
"to filesystems and their snapshots\n"));
zfs_close(zhp);
Expand Down
11 changes: 6 additions & 5 deletions cmd/zpool_influxdb/zpool_influxdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <libzfs_impl.h>
#include <libzfs.h>

#define POOL_MEASUREMENT "zpool_stats"
#define SCAN_MEASUREMENT "zpool_scan_stats"
Expand Down Expand Up @@ -101,9 +101,10 @@ typedef int (*stat_printer_f)(nvlist_t *, const char *, const char *);
* caller is responsible for freeing result
*/
static char *
escape_string(char *s)
escape_string(const char *s)
{
char *c, *d;
const char *c;
char *d;
char *t = (char *)malloc(ZFS_MAX_DATASET_NAME_LEN * 2);
if (t == NULL) {
fprintf(stderr, "error: cannot allocate memory\n");
Expand Down Expand Up @@ -714,7 +715,7 @@ print_stats(zpool_handle_t *zhp, void *data)

/* if not this pool return quickly */
if (data &&
strncmp(data, zhp->zpool_name, ZFS_MAX_DATASET_NAME_LEN) != 0) {
strncmp(data, zpool_get_name(zhp), ZFS_MAX_DATASET_NAME_LEN) != 0) {
zpool_close(zhp);
return (0);
}
Expand Down Expand Up @@ -742,7 +743,7 @@ print_stats(zpool_handle_t *zhp, void *data)
return (3);
}

pool_name = escape_string(zhp->zpool_name);
pool_name = escape_string(zpool_get_name(zhp));
err = print_recursive_stats(print_summary_stats, nvroot,
pool_name, NULL, 1);
/* if any of these return an error, skip the rest */
Expand Down
1 change: 0 additions & 1 deletion cmd/zstream/zstream_redup.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <libzfs_impl.h>
#include <libzfs.h>
#include <libzutil.h>
#include <stddef.h>
Expand Down
1 change: 1 addition & 0 deletions include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
extern zfs_handle_t *zfs_handle_dup(zfs_handle_t *);
extern void zfs_close(zfs_handle_t *);
extern zfs_type_t zfs_get_type(const zfs_handle_t *);
extern zfs_type_t zfs_get_underlying_type(const zfs_handle_t *);
extern const char *zfs_get_name(const zfs_handle_t *);
extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
extern const char *zfs_get_pool_name(const zfs_handle_t *);
Expand Down
Loading

0 comments on commit 222d2be

Please sign in to comment.