Bug 244054 - net/samba410: LIBZFS option?
Summary: net/samba410: LIBZFS option?
Status: In Progress
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Timur I. Bakeyev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-11 22:40 UTC by Mathieu Arnold
Modified: 2020-04-22 07:16 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (timur)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mathieu Arnold freebsd_committer 2020-02-11 22:40:44 UTC
There are a few references to a LIBZFS option, but it is missing from OPTIONS_DEFINE.  As it seems to enable a vfs_zfs_space module that is referenced by a lot of howtos, I am wondering what the status of that option is.
Comment 1 Timur I. Bakeyev freebsd_committer 2020-02-12 09:53:26 UTC
(In reply to Mathieu Arnold from comment #0)

Well, libZFS is a library developed(or packaged) by iXsystems, as well as vfs_zfs_space module, which is developed by them.

The problem with the libZFS is that to package it you need to have current kernel sources, which is a bit tricky to ensure in the generic ports environment.

Or, maybe, I'm missing some obvious solution.

I have preliminary port of libZFS, but I can't resolve that dependency reliably, hence it's not available to GP...

If you can come up with any reasonable suggestion - I'd be glad to push it to the ports.

It's also possible that with the planned switch to ZFSoL codebase we'd get libZFS automatically(but I'm not certain, what are developments there in that regards).
Comment 2 Timur I. Bakeyev freebsd_committer 2020-02-12 10:04:54 UTC
(In reply to Mathieu Arnold from comment #0)

Or, to be more precise, liZFS is there, in [/usr/]lib/libzfs.so. But to be able to  compile any code to link with it you need to supply all the relevant kernel headers, which have to match the version of libzfs in the system. And I saw in the past disasters due the desync of those.

Otherwise the code is pretty simple:

```
FREEBSD_SRC=/usr/src

cc \
-I"${FREEBSD_SRC}/cddl/compat/opensolaris/include" \
-I"${FREEBSD_SRC}/cddl/compat/opensolaris/lib/libumem" \
-I"${FREEBSD_SRC}/cddl/contrib/opensolaris/head" \
-I"${FREEBSD_SRC}/cddl/contrib/opensolaris/lib/libnvpair" \
-I"${FREEBSD_SRC}/cddl/contrib/opensolaris/lib/libumem/common" \
-I"${FREEBSD_SRC}/cddl/contrib/opensolaris/lib/libuutil/common" \
-I"${FREEBSD_SRC}/cddl/contrib/opensolaris/lib/libzfs_core/common" \
-I"${FREEBSD_SRC}/cddl/contrib/opensolaris/lib/libzfs/common" \
-I"${FREEBSD_SRC}/cddl/contrib/opensolaris/lib/libzpool/common" \
-I"${FREEBSD_SRC}/sys/cddl/compat/opensolaris" \
-I"${FREEBSD_SRC}/sys/cddl/contrib/opensolaris/common/zfs" \
-I"${FREEBSD_SRC}/sys/cddl/contrib/opensolaris/uts/common" \
-I"${FREEBSD_SRC}/sys/cddl/contrib/opensolaris/uts/common/fs/zfs" \
-I"${FREEBSD_SRC}/sys/cddl/contrib/opensolaris/uts/common/sys" \
-lzfs \
"$@"
```
Comment 3 Timur I. Bakeyev freebsd_committer 2020-02-12 10:05:55 UTC
And getting freespace on ZFS is merely:

```
#define NEED_SOLARIS_BOOLEAN

#include <sys/types.h>
#include <libzfs.h>
#include <err.h>

int get_space(char *path) {
        size_t blocksize = 1024;
        libzfs_handle_t *libzfsp;
        zfs_handle_t *zfsp;
        uint64_t available, usedbysnapshots, usedbydataset,
                usedbychildren, usedbyrefreservation, real_used, total;

        if (path == NULL) {
                warn("No way");
                return (-1);
        }

        if ((libzfsp = libzfs_init()) == NULL) {
                warn("failed to initialize lib");
                return (-1);
        }

        libzfs_print_on_error(libzfsp, B_TRUE);

        zfsp = zfs_path_to_zhandle(libzfsp, path,
                ZFS_TYPE_VOLUME|ZFS_TYPE_DATASET|ZFS_TYPE_FILESYSTEM);
        if (zfsp == NULL) {
                warn("No zhandle");
                return (-1);
        }

        available = zfs_prop_get_int(zfsp, ZFS_PROP_AVAILABLE);
        usedbysnapshots = zfs_prop_get_int(zfsp, ZFS_PROP_USEDSNAP);
        usedbydataset = zfs_prop_get_int(zfsp, ZFS_PROP_USEDDS);
        usedbychildren = zfs_prop_get_int(zfsp, ZFS_PROP_USEDCHILD);
        usedbyrefreservation = zfs_prop_get_int(zfsp, ZFS_PROP_USEDREFRESERV);

        warn("%ld %ld %ld %ld\n", available, usedbysnapshots, usedbydataset, usedbychildren);

        zfs_close(zfsp);
        libzfs_fini(libzfsp);
        return 0;
}

int main(int argc, char *argv[]) {
        get_space(argv[1]);
        return 0;
}
```
Comment 4 Mathieu Arnold freebsd_committer 2020-02-12 10:44:59 UTC
I don't understand your problem.  There are many many examples of ports that require the kernel sources to be present.  To name one that is related to what we are talking about, devel/py-libzfs.

You simply do:

    .include <bsd.port.options.mk>
    
    .if !exists(${SRC_BASE}/sys/Makefile)
    IGNORE= requires kernel source files in ${SRC_BASE}
    .endif

you do not have to take care about people having sources and running kernel out of sync, it's their problem, not yours.
Comment 5 Lapo Luchini 2020-04-22 07:16:07 UTC
BTW: FreeNAS GitHub repo has a patched net/samba411 port which has this (and also vfs_shadow_copy_zfs):

https://github.com/freenas/ports/tree/freenas/master/net/samba411