From cb4f9ea88944b0394f5fd4ba5aa09a67b29e5163 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 15 Dec 2011 06:16:51 +0100 Subject: [PATCH 01/15] Empty framework created with a little README what's required and how to test functionality. --- lib/libshare/Makefile.am | 6 +- lib/libshare/Makefile.in | 19 ++++- lib/libshare/README_smb.txt | 53 +++++++++++++ lib/libshare/libshare.c | 2 + lib/libshare/smb.c | 153 ++++++++++++++++++++++++++++++++++++ lib/libshare/smb.h | 27 +++++++ 6 files changed, 255 insertions(+), 5 deletions(-) create mode 100644 lib/libshare/README_smb.txt create mode 100644 lib/libshare/smb.c create mode 100644 lib/libshare/smb.h diff --git a/lib/libshare/Makefile.am b/lib/libshare/Makefile.am index b66df8c56e86..b31284a5b151 100644 --- a/lib/libshare/Makefile.am +++ b/lib/libshare/Makefile.am @@ -8,8 +8,10 @@ lib_LTLIBRARIES = libshare.la libshare_la_SOURCES = \ $(top_srcdir)/lib/libshare/libshare.c \ - $(top_srcdir)/lib/libshare/nfs.c \ $(top_srcdir)/lib/libshare/libshare_impl.h \ - $(top_srcdir)/lib/libshare/nfs.h + $(top_srcdir)/lib/libshare/nfs.c \ + $(top_srcdir)/lib/libshare/nfs.h \ + $(top_srcdir)/lib/libshare/smb.c \ + $(top_srcdir)/lib/libshare/smb.h libshare_la_LDFLAGS = -version-info 1:0:0 diff --git a/lib/libshare/Makefile.in b/lib/libshare/Makefile.in index 3705c7d28fec..ff5944f7e8cf 100644 --- a/lib/libshare/Makefile.in +++ b/lib/libshare/Makefile.in @@ -114,7 +114,7 @@ am__base_list = \ am__installdirs = "$(DESTDIR)$(libdir)" LTLIBRARIES = $(lib_LTLIBRARIES) libshare_la_LIBADD = -am_libshare_la_OBJECTS = libshare.lo nfs.lo +am_libshare_la_OBJECTS = libshare.lo nfs.lo smb.lo libshare_la_OBJECTS = $(am_libshare_la_OBJECTS) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) @@ -333,11 +333,14 @@ AM_CFLAGS = -Wall -Wstrict-prototypes -fno-strict-aliasing \ lib_LTLIBRARIES = libshare.la libshare_la_SOURCES = \ $(top_srcdir)/lib/libshare/libshare.c \ - $(top_srcdir)/lib/libshare/nfs.c \ $(top_srcdir)/lib/libshare/libshare_impl.h \ - $(top_srcdir)/lib/libshare/nfs.h + $(top_srcdir)/lib/libshare/nfs.c \ + $(top_srcdir)/lib/libshare/nfs.h \ + $(top_srcdir)/lib/libshare/smb.c \ + $(top_srcdir)/lib/libshare/smb.h libshare_la_LDFLAGS = -version-info 1:0:0 + all: all-am .SUFFIXES: @@ -414,6 +417,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libshare.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nfs.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smb.Plo@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -455,6 +459,15 @@ nfs.lo: $(top_srcdir)/lib/libshare/nfs.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o nfs.lo `test -f '$(top_srcdir)/lib/libshare/nfs.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/libshare/nfs.c +smb.lo: $(top_srcdir)/lib/libshare/smb.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT smb.lo -MD -MP -MF $(DEPDIR)/smb.Tpo -c -o smb.lo `test -f '$(top_srcdir)/lib/libshare/smb.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/libshare/smb.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/smb.Tpo $(DEPDIR)/smb.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/lib/libshare/smb.c' object='smb.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o smb.lo `test -f '$(top_srcdir)/lib/libshare/smb.c' || echo '$(srcdir)/'`$(top_srcdir)/lib/libshare/smb.c + + mostlyclean-libtool: -rm -f *.lo diff --git a/lib/libshare/README_smb.txt b/lib/libshare/README_smb.txt new file mode 100644 index 000000000000..ad611e248258 --- /dev/null +++ b/lib/libshare/README_smb.txt @@ -0,0 +1,53 @@ +This is basic information about the 'sharesmb' option in ZFS +On Linux by Turbo Fredriksson . + +REQUIRENMENTS +============================================================ +1. Samba (doh! :) + * I'm using version 3.3.3, but any 3.x should + probably work. Please update the tracker with + info.. + +2. The following configuration in smb.conf + + add share command = /usr/local/sbin/modify_samba_config.pl + delete share command = /usr/local/sbin/modify_samba_config.pl + change share command = /usr/local/sbin/modify_samba_config.pl + + include = /etc/samba/shares.conf-dynamic + + The script (modify_samba_config.pl) comes in two + versions, one perl and one python and can be found + in the samba source directory: + + ./examples/scripts/shares/perl/modify_samba_config.pl + ./examples/scripts/shares/python/modify_samba_config.py + + Personaly, I choosed the perl version and modified + it slightly - to not overwrite or modify smb.conf, + but instead the /etc/samba/shares.conf-dynamic file, + which is completely managed by the zfs/net commands. + +3. Samba will need to listen to 'localhost' (127.0.0.1), + because that is hardcoded into the zfs module/libraries. + +4. A workable root password. ZFS is using 'root' as samba + account to add, modify and remove shares so this need + to work. + +5. A ZFS filesystem or more to export. + + +TESTING +============================================================ +Once configuration in samba have been done, test that this +works with the following commands (in this case, my ZFS +filesystem is called 'share/Test1'): + + net -U root -S 127.0.0.1 share add Test1=/share/Test1 + net share list | grep -i test + net -U root -S 127.0.0.1 share delete Test1 + +The first and second command will ask for a root password +and the second (middle) command should give at least one +line. diff --git a/lib/libshare/libshare.c b/lib/libshare/libshare.c index c34e83919402..6b39ba8724e2 100644 --- a/lib/libshare/libshare.c +++ b/lib/libshare/libshare.c @@ -36,6 +36,7 @@ #include #include "libshare_impl.h" #include "nfs.h" +#include "smb.h" static sa_share_impl_t find_share(sa_handle_impl_t handle, const char *sharepath); @@ -103,6 +104,7 @@ __attribute__((constructor)) static void libshare_init(void) { libshare_nfs_init(); + libshare_smb_init(); /* * This bit causes /etc/dfs/sharetab to be updated before libzfs gets a diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c new file mode 100644 index 000000000000..ef5a849a6a49 --- /dev/null +++ b/lib/libshare/smb.c @@ -0,0 +1,153 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011 Turbo Fredriksson + * + * This is an addition to the zfs device driver to add, modify and remove SMB + * shares using the 'net share' command that comes with Samba. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "libshare_impl.h" +#include "smb.h" + +static sa_fstype_t *smb_fstype; +boolean_t smb_available; + +int +smb_enable_share_one(void) +{ +fprintf(stderr, "smb_enable_share_one()\n"); + return 0; +} + +int +smb_enable_share(sa_share_impl_t impl_share) +{ +fprintf(stderr, "smb_enable_share()\n"); + return 0; +} + +int +smb_disable_share_one(void) +{ +fprintf(stderr, "smb_disable_share_one()\n"); + return 0; +} + +int +smb_disable_share(sa_share_impl_t impl_share) +{ +fprintf(stderr, "smb_disable_share()\n"); + return 0; +} + +static boolean_t +smb_is_share_active(sa_share_impl_t impl_share) +{ +fprintf(stderr, "smb_is_share_active()\n"); + return 0; +} + +static int +smb_validate_shareopts(const char *shareopts) +{ + /* TODO: implement */ + return 0; +} + +static int +smb_update_shareopts(sa_share_impl_t impl_share, const char *resource, + const char *shareopts) +{ + char *shareopts_dup; + boolean_t needs_reshare = B_FALSE; + char *old_shareopts; +fprintf(stderr, "smb_update_shareopts()\n"); + + FSINFO(impl_share, smb_fstype)->active = smb_is_share_active(impl_share); + + old_shareopts = FSINFO(impl_share, smb_fstype)->shareopts; + + if (FSINFO(impl_share, smb_fstype)->active && old_shareopts != NULL && + strcmp(old_shareopts, shareopts) != 0) { + needs_reshare = B_TRUE; + smb_disable_share(impl_share); + } + + shareopts_dup = strdup(shareopts); + + if (shareopts_dup == NULL) + return SA_NO_MEMORY; + + if (old_shareopts != NULL) + free(old_shareopts); + + FSINFO(impl_share, smb_fstype)->shareopts = shareopts_dup; + + if (needs_reshare) + smb_enable_share(impl_share); + + return 0; +} + +static void +smb_clear_shareopts(sa_share_impl_t impl_share) +{ +fprintf(stderr, "smb_clear_shareopts()\n"); + free(FSINFO(impl_share, smb_fstype)->shareopts); + FSINFO(impl_share, smb_fstype)->shareopts = NULL; +} + +static const sa_share_ops_t smb_shareops = { + .enable_share = smb_enable_share, + .disable_share = smb_disable_share, + + .validate_shareopts = smb_validate_shareopts, + .update_shareopts = smb_update_shareopts, + .clear_shareopts = smb_clear_shareopts, +}; + +int +smb_retrieve_shares(void) +{ +fprintf(stderr, " smb_retrieve_shares()\n"); + return 1; +} + +void +libshare_smb_init(void) +{ +fprintf(stderr, "libshare_smb_init()\n"); + smb_available = (smb_retrieve_shares() == SA_OK); + + smb_fstype = register_fstype("smb", &smb_shareops); +} diff --git a/lib/libshare/smb.h b/lib/libshare/smb.h new file mode 100644 index 000000000000..5914ec5be17f --- /dev/null +++ b/lib/libshare/smb.h @@ -0,0 +1,27 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011 Turbo Fredriksson . + */ + +void libshare_smb_init(void); From b5493c8f2e36de213ecd94161124ae9865b5ae2d Mon Sep 17 00:00:00 2001 From: root Date: Thu, 15 Dec 2011 09:34:27 +0100 Subject: [PATCH 02/15] Enable share is good... --- lib/libshare/smb.c | 105 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 6 deletions(-) diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c index ef5a849a6a49..6c0a77e8aab4 100644 --- a/lib/libshare/smb.c +++ b/lib/libshare/smb.c @@ -42,24 +42,112 @@ static sa_fstype_t *smb_fstype; boolean_t smb_available; +int smb_retrieve_shares(void); + +/* + * By Jerome Bettis + * http://ubuntuforums.org/showthread.php?t=141670 + */ +static void +strrep(char *str, char old, char new) +{ + char *pos; + + if (new == old) + return; + + pos = strchr(str, old); + while (pos != NULL) { + *pos = new; + pos = strchr(pos + 1, old); + } +} + int -smb_enable_share_one(void) +smb_enable_share_one(const char *sharename, const char *sharepath) { -fprintf(stderr, "smb_enable_share_one()\n"); + char *argv[10], name_path[255], name[255]; + int rc; + +// DEBUG +fprintf(stderr, " smb_enable_share_one(%s, %s)\n", + sharename, sharepath); + + /* Remove the slash(es) in the share name */ + strncpy(name, sharename, sizeof(name)); + strrep(name, '/', '_'); + + /* + * CMD: net -U root -S 127.0.0.1 share add Test1=/share/Test1 + */ + + snprintf(name_path, sizeof(name_path), "%s=%s", name, sharepath); + + argv[0] = "/usr/bin/net"; + argv[1] = "-U"; + argv[2] = "root"; + argv[3] = "-S"; + argv[4] = "127.0.0.1"; + argv[5] = "share"; + argv[6] = "add"; + argv[7] = name_path; + argv[8] = NULL; + + int i; + fprintf(stderr, "CMD: "); + for (i=0; i < 8; i++) { + fprintf(stderr, "%s ", argv[i]); + } + fprintf(stderr, "\n"); + + rc = libzfs_run_process(argv[0], argv, 0); + if (rc < 0) + return SA_SYSTEM_ERR; + + /* Reload the share file */ + smb_retrieve_shares(); + return 0; } int smb_enable_share(sa_share_impl_t impl_share) { -fprintf(stderr, "smb_enable_share()\n"); - return 0; + char *shareopts; + +// DEBUG +fprintf(stderr, "smb_enable_share(): dataset=%s\n", impl_share->dataset); + + if (!smb_available) { +// DEBUG +fprintf(stderr, " smb_enable_share(): -> !smb_available\n"); + return SA_SYSTEM_ERR; + } + + shareopts = FSINFO(impl_share, smb_fstype)->shareopts; + if (shareopts == NULL) { /* on/off */ +// DEBUG +fprintf(stderr, " smb_enable_share(): -> SA_SYSTEM_ERR\n"); + return SA_SYSTEM_ERR; + } + + if (strcmp(shareopts, "off") == 0) { +// DEBUG +fprintf(stderr, " smb_enable_share(): -> off (0)\n"); + return (0); + } + + /* Magic: Enable (i.e., 'create new') share */ + return smb_enable_share_one(impl_share->dataset, + impl_share->sharepath); } int smb_disable_share_one(void) { fprintf(stderr, "smb_disable_share_one()\n"); + /* CMD: net -U root -S 127.0.0.1 share delete Test1 */ + return 0; } @@ -74,7 +162,7 @@ static boolean_t smb_is_share_active(sa_share_impl_t impl_share) { fprintf(stderr, "smb_is_share_active()\n"); - return 0; + return B_FALSE; } static int @@ -139,8 +227,13 @@ static const sa_share_ops_t smb_shareops = { int smb_retrieve_shares(void) { + int rc = SA_OK; + fprintf(stderr, " smb_retrieve_shares()\n"); - return 1; + + /* CMD: net share list */ + + return rc; } void From d68638414c4e78139c877ac198d5fb5095cb0262 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 15 Dec 2011 10:21:45 +0100 Subject: [PATCH 03/15] Go with usershare instead of systemshare. Less modification to system configs and are easier to list and parse. --- lib/libshare/README_smb.txt | 42 ++++++++---------------------- lib/libshare/smb.c | 52 ++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 55 deletions(-) diff --git a/lib/libshare/README_smb.txt b/lib/libshare/README_smb.txt index ad611e248258..4c8e754b29f5 100644 --- a/lib/libshare/README_smb.txt +++ b/lib/libshare/README_smb.txt @@ -8,34 +8,14 @@ REQUIRENMENTS probably work. Please update the tracker with info.. -2. The following configuration in smb.conf - - add share command = /usr/local/sbin/modify_samba_config.pl - delete share command = /usr/local/sbin/modify_samba_config.pl - change share command = /usr/local/sbin/modify_samba_config.pl - - include = /etc/samba/shares.conf-dynamic - - The script (modify_samba_config.pl) comes in two - versions, one perl and one python and can be found - in the samba source directory: - - ./examples/scripts/shares/perl/modify_samba_config.pl - ./examples/scripts/shares/python/modify_samba_config.py - - Personaly, I choosed the perl version and modified - it slightly - to not overwrite or modify smb.conf, - but instead the /etc/samba/shares.conf-dynamic file, - which is completely managed by the zfs/net commands. - -3. Samba will need to listen to 'localhost' (127.0.0.1), +2. Samba will need to listen to 'localhost' (127.0.0.1), because that is hardcoded into the zfs module/libraries. -4. A workable root password. ZFS is using 'root' as samba - account to add, modify and remove shares so this need - to work. +3. Some configuration settings in samba: + + usershare max shares = 100 -5. A ZFS filesystem or more to export. +4. A ZFS filesystem or more to export. TESTING @@ -44,10 +24,10 @@ Once configuration in samba have been done, test that this works with the following commands (in this case, my ZFS filesystem is called 'share/Test1'): - net -U root -S 127.0.0.1 share add Test1=/share/Test1 - net share list | grep -i test - net -U root -S 127.0.0.1 share delete Test1 + net -U root -S 127.0.0.1 usershare add Test1 /share/Test1 "Comment: /share/Test1" "Everyone:F" + net usershare list | grep -i test + net -U root -S 127.0.0.1 usershare delete Test1 -The first and second command will ask for a root password -and the second (middle) command should give at least one -line. +The first command will create a user share that gives +everyone full access. To limit the access below that, +use normal UNIX commands (chmod, chown etc). diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c index 6c0a77e8aab4..0366458ca4ed 100644 --- a/lib/libshare/smb.c +++ b/lib/libshare/smb.c @@ -66,7 +66,7 @@ strrep(char *str, char old, char new) int smb_enable_share_one(const char *sharename, const char *sharepath) { - char *argv[10], name_path[255], name[255]; + char *argv[12], name[255], comment[255]; int rc; // DEBUG @@ -78,27 +78,23 @@ fprintf(stderr, " smb_enable_share_one(%s, %s)\n", strrep(name, '/', '_'); /* - * CMD: net -U root -S 127.0.0.1 share add Test1=/share/Test1 + * CMD: net -U root -S 127.0.0.1 usershare add Test1 /share/Test1 "Comment" "Everyone:F" */ - snprintf(name_path, sizeof(name_path), "%s=%s", name, sharepath); - - argv[0] = "/usr/bin/net"; - argv[1] = "-U"; - argv[2] = "root"; - argv[3] = "-S"; - argv[4] = "127.0.0.1"; - argv[5] = "share"; - argv[6] = "add"; - argv[7] = name_path; - argv[8] = NULL; - - int i; - fprintf(stderr, "CMD: "); - for (i=0; i < 8; i++) { - fprintf(stderr, "%s ", argv[i]); - } - fprintf(stderr, "\n"); + snprintf(comment, sizeof (comment), "Comment: %s", sharepath); + + argv[0] = "/usr/bin/net"; + argv[1] = "-U"; + argv[2] = "root"; + argv[3] = "-S"; + argv[4] = "127.0.0.1"; + argv[5] = "usershare"; + argv[6] = "add"; + argv[7] = name; + argv[8] = strdup(sharepath); + argv[9] = comment; + argv[10] = "Everyone:F"; + argv[11] = NULL; rc = libzfs_run_process(argv[0], argv, 0); if (rc < 0) @@ -143,10 +139,15 @@ fprintf(stderr, " smb_enable_share(): -> off (0)\n"); } int -smb_disable_share_one(void) +smb_disable_share_one(int sid) { + int rc; + char *argv[6]; + +// DEBUG fprintf(stderr, "smb_disable_share_one()\n"); - /* CMD: net -U root -S 127.0.0.1 share delete Test1 */ + + /* CMD: net -U root -S 127.0.0.1 usershare delete Test1 */ return 0; } @@ -179,6 +180,7 @@ smb_update_shareopts(sa_share_impl_t impl_share, const char *resource, char *shareopts_dup; boolean_t needs_reshare = B_FALSE; char *old_shareopts; +// DEBUG fprintf(stderr, "smb_update_shareopts()\n"); FSINFO(impl_share, smb_fstype)->active = smb_is_share_active(impl_share); @@ -210,6 +212,7 @@ fprintf(stderr, "smb_update_shareopts()\n"); static void smb_clear_shareopts(sa_share_impl_t impl_share) { +// DEBUG fprintf(stderr, "smb_clear_shareopts()\n"); free(FSINFO(impl_share, smb_fstype)->shareopts); FSINFO(impl_share, smb_fstype)->shareopts = NULL; @@ -228,10 +231,10 @@ int smb_retrieve_shares(void) { int rc = SA_OK; - +// DEBUG fprintf(stderr, " smb_retrieve_shares()\n"); - /* CMD: net share list */ + /* CMD: net usershare list -l */ return rc; } @@ -239,6 +242,7 @@ fprintf(stderr, " smb_retrieve_shares()\n"); void libshare_smb_init(void) { +// DEBUG fprintf(stderr, "libshare_smb_init()\n"); smb_available = (smb_retrieve_shares() == SA_OK); From 7d9d80d103ac34066a7c182799567f619078e3e0 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 16 Dec 2011 13:15:45 +0100 Subject: [PATCH 04/15] * Load usershares from /var/lib/samba/usershares + Create the linked list smb_shares with this information. * Disable share using 'net usershare delete' --- lib/libshare/smb.c | 185 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 177 insertions(+), 8 deletions(-) diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c index 0366458ca4ed..48c8b205a5f4 100644 --- a/lib/libshare/smb.c +++ b/lib/libshare/smb.c @@ -34,13 +34,26 @@ #include #include #include +#include #include #include #include "libshare_impl.h" #include "smb.h" +typedef struct smb_share_s { + char name[255]; /* Share name */ + char path[255]; /* Share path */ + char comment[255]; /* Share's comment */ + boolean_t guest_ok; /* 'y' or 'n' */ + + struct smb_share_s *next; +} smb_share_t; + static sa_fstype_t *smb_fstype; boolean_t smb_available; +smb_share_t *smb_shares; + +#define SHARE_DIR "/var/lib/samba/usershares" int smb_retrieve_shares(void); @@ -96,6 +109,13 @@ fprintf(stderr, " smb_enable_share_one(%s, %s)\n", argv[10] = "Everyone:F"; argv[11] = NULL; +int i; +fprintf(stderr, " CMD: "); +for (i=0; argv[i] != NULL; i++) { + fprintf(stderr, "%s ", argv[i]); +} +fprintf(stderr, "\n"); + rc = libzfs_run_process(argv[0], argv, 0); if (rc < 0) return SA_SYSTEM_ERR; @@ -112,7 +132,8 @@ smb_enable_share(sa_share_impl_t impl_share) char *shareopts; // DEBUG -fprintf(stderr, "smb_enable_share(): dataset=%s\n", impl_share->dataset); +fprintf(stderr, "smb_enable_share(): dataset=%s, path=%s\n", + impl_share->dataset, impl_share->sharepath); if (!smb_available) { // DEBUG @@ -139,30 +160,71 @@ fprintf(stderr, " smb_enable_share(): -> off (0)\n"); } int -smb_disable_share_one(int sid) +smb_disable_share_one(const char *sharename) { - int rc; + int rc = SA_OK; char *argv[6]; // DEBUG -fprintf(stderr, "smb_disable_share_one()\n"); +fprintf(stderr, " smb_disable_share_one()\n"); /* CMD: net -U root -S 127.0.0.1 usershare delete Test1 */ + argv[0] = "/usr/bin/net"; + argv[1] = "usershare"; + argv[2] = "delete"; + argv[3] = strdup(sharename); + argv[4] = NULL; + +int i; +fprintf(stderr, " CMD: "); +for (i=0; argv[i] != NULL; i++) { + fprintf(stderr, "%s ", argv[i]); +} +fprintf(stderr, "\n"); - return 0; + rc = libzfs_run_process(argv[0], argv, 0); + if (rc < 0) + return SA_SYSTEM_ERR; + + return rc; } int smb_disable_share(sa_share_impl_t impl_share) { -fprintf(stderr, "smb_disable_share()\n"); + smb_share_t *shares = smb_shares; + +fprintf(stderr, " smb_disable_share(): dataset=%s, path=%s\n", + impl_share->dataset, impl_share->sharepath); + + while (shares != NULL) { + if (strcmp(impl_share->sharepath, shares->path) == 0) + return smb_disable_share_one(shares->name); + + shares = shares->next; + } + + /* Reload the share file */ + smb_retrieve_shares(); + return 0; } static boolean_t smb_is_share_active(sa_share_impl_t impl_share) { -fprintf(stderr, "smb_is_share_active()\n"); + smb_share_t *shares = smb_shares; + +fprintf(stderr, " smb_is_share_active(): dataset=%s, path=%s\n", + impl_share->dataset, impl_share->sharepath); + + while (shares != NULL) { + if (strcmp(impl_share->sharepath, shares->path) == 0) + return B_TRUE; + + shares = shares->next; + } + return B_FALSE; } @@ -231,10 +293,117 @@ int smb_retrieve_shares(void) { int rc = SA_OK; + char file_path[255], line[512], *token, *key, *value, *dup_value; + char *path = NULL, *comment = NULL, *name = NULL, *guest_ok = NULL; + DIR *shares_dir; + FILE *share_file_fp; + struct dirent *directory; + smb_share_t *shares, *new_shares = NULL; + // DEBUG fprintf(stderr, " smb_retrieve_shares()\n"); - /* CMD: net usershare list -l */ + /* opendir(), stat() */ + shares_dir = opendir(SHARE_DIR); + if (shares_dir == NULL) { +// DEBUG +fprintf(stderr, " opendir() == NULL\n"); + return SA_SYSTEM_ERR; + } + + /* Go through the directory, looking for shares */ + while ((directory = readdir(shares_dir))) { + if ((directory->d_name[0] == '.') || + (directory->d_type != 8)) /* DT_REG (regular file) if using _BSD_SOURCE */ + continue; +// DEBUG +fprintf(stderr, " %s\n", directory->d_name); + + snprintf(file_path, sizeof (file_path), + "%s/%s", SHARE_DIR, directory->d_name); + if ((share_file_fp = fopen(file_path, "r")) == NULL) { +// DEBUG +fprintf(stderr, " fopen() == NULL\n"); + rc = SA_SYSTEM_ERR; + goto out; + } + + name = strdup(directory->d_name); + if (name == NULL) { + rc = SA_NO_MEMORY; + goto out; + } + + while (fgets(line, sizeof(line), share_file_fp)) { + if (line[0] == '#') + continue; + + /* Trim trailing new-line character(s). */ + while (line[strlen(line) - 1] == '\r' || + line[strlen(line) - 1] == '\n') + line[strlen(line) - 1] = '\0'; + +// DEBUG +fprintf(stderr, " %s ", line); + + /* Split the line in two, separated by '=' */ + token = strchr(line, '='); + if (token == NULL) + continue; + + key = line; + value = token + 1; + *token = '\0'; +// DEBUG +fprintf(stderr, "(%s = %s)\n", key, value); + + dup_value = strdup(value); + if (dup_value == NULL) + exit(SA_NO_MEMORY); + + if (strcmp(key, "path") == 0) + path = dup_value; + if (strcmp(key, "comment") == 0) + comment = dup_value; + if (strcmp(key, "guest_ok") == 0) + guest_ok = dup_value; + + if (path == NULL || comment == NULL || guest_ok == NULL) + continue; /* Incomplete share definition */ + else { + shares = (smb_share_t *)malloc(sizeof (smb_share_t)); + if (shares == NULL) { + rc = SA_NO_MEMORY; + goto out; + } + + strncpy(shares->name, name, sizeof (shares->name)); + strncpy(shares->path, path, sizeof (shares->path)); + strncpy(shares->comment, comment, sizeof (shares->comment)); + shares->guest_ok = atoi(guest_ok); + + shares->next = new_shares; + new_shares = shares; + + name = NULL; + path = NULL; + comment = NULL; + guest_ok = NULL; + } + } + +out: + if (share_file_fp != NULL) + fclose(share_file_fp); + + free(name); + free(path); + free(comment); + free(guest_ok); + } + closedir(shares_dir); + + smb_shares = new_shares; return rc; } From eb1a5828e321eacb288bc7efe7ce59bf357b41c0 Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Fri, 16 Dec 2011 22:41:36 +0100 Subject: [PATCH 05/15] * Replace strrep() with code by dajhorn instead - licensing issues. + Replace / - : and space with _ * Function to check if a file is executable - file_is_executable(). + Use this to check that the command we're trying to exec is actually executable. * Put all debugging inside ifdef/endif and indented. --- lib/libshare/libshare.c | 9 ++ lib/libshare/libshare_impl.h | 1 + lib/libshare/smb.c | 168 ++++++++++++++++++++--------------- lib/libshare/smb.h | 1 - 4 files changed, 104 insertions(+), 75 deletions(-) diff --git a/lib/libshare/libshare.c b/lib/libshare/libshare.c index 6b39ba8724e2..42e63b869903 100644 --- a/lib/libshare/libshare.c +++ b/lib/libshare/libshare.c @@ -56,6 +56,15 @@ static int update_zfs_shares(sa_handle_impl_t impl_handle, const char *proto); static int fstypes_count; static sa_fstype_t *fstypes; +int +file_exists(char *file_name) +{ + if ((access(file_name, X_OK)) == 0) + /* File found */ + return SA_OK; + return SA_NO_SUCH_PATH; +} + sa_fstype_t * register_fstype(const char *name, const sa_share_ops_t *ops) { diff --git a/lib/libshare/libshare_impl.h b/lib/libshare/libshare_impl.h index dfcec2ff9775..c299dff19dd2 100644 --- a/lib/libshare/libshare_impl.h +++ b/lib/libshare/libshare_impl.h @@ -68,3 +68,4 @@ typedef struct sa_handle_impl { } *sa_handle_impl_t; sa_fstype_t *register_fstype(const char *name, const sa_share_ops_t *ops); +int file_exists (char *); diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c index 48c8b205a5f4..22eeb5febc45 100644 --- a/lib/libshare/smb.c +++ b/lib/libshare/smb.c @@ -54,49 +54,45 @@ boolean_t smb_available; smb_share_t *smb_shares; #define SHARE_DIR "/var/lib/samba/usershares" +#define NET_CMD_PATH "/usr/bin/net" int smb_retrieve_shares(void); -/* - * By Jerome Bettis - * http://ubuntuforums.org/showthread.php?t=141670 - */ -static void -strrep(char *str, char old, char new) -{ - char *pos; - - if (new == old) - return; - - pos = strchr(str, old); - while (pos != NULL) { - *pos = new; - pos = strchr(pos + 1, old); - } -} - int smb_enable_share_one(const char *sharename, const char *sharepath) { char *argv[12], name[255], comment[255]; int rc; -// DEBUG -fprintf(stderr, " smb_enable_share_one(%s, %s)\n", - sharename, sharepath); +#ifdef DEBUG + fprintf(stderr, " smb_enable_share_one(%s, %s)\n", + sharename, sharepath); +#endif - /* Remove the slash(es) in the share name */ + /* Support ZFS share name regexp '[[:alnum:]_-.: ]' */ strncpy(name, sharename, sizeof(name)); - strrep(name, '/', '_'); - /* - * CMD: net -U root -S 127.0.0.1 usershare add Test1 /share/Test1 "Comment" "Everyone:F" - */ + char *pos = name; + if( pos == NULL ) + return; + + while( *pos != '\0' ) { + switch( *pos ) { + case '/': + case '-': + case ':': + case ' ': + *pos = '_'; + } + ++pos; + } + /* CMD: net -U root -S 127.0.0.1 usershare add Test1 /share/Test1 "Comment" "Everyone:F" */ snprintf(comment, sizeof (comment), "Comment: %s", sharepath); - argv[0] = "/usr/bin/net"; + if (file_exists(NET_CMD_PATH)) + return SA_SYSTEM_ERR; + argv[0] = NET_CMD_PATH; argv[1] = "-U"; argv[2] = "root"; argv[3] = "-S"; @@ -109,12 +105,14 @@ fprintf(stderr, " smb_enable_share_one(%s, %s)\n", argv[10] = "Everyone:F"; argv[11] = NULL; -int i; -fprintf(stderr, " CMD: "); -for (i=0; argv[i] != NULL; i++) { - fprintf(stderr, "%s ", argv[i]); -} -fprintf(stderr, "\n"); +#endif + int i; + fprintf(stderr, " CMD: "); + for (i=0; argv[i] != NULL; i++) { + fprintf(stderr, "%s ", argv[i]); + } + fprintf(stderr, "\n"); +#endif rc = libzfs_run_process(argv[0], argv, 0); if (rc < 0) @@ -131,26 +129,30 @@ smb_enable_share(sa_share_impl_t impl_share) { char *shareopts; -// DEBUG -fprintf(stderr, "smb_enable_share(): dataset=%s, path=%s\n", - impl_share->dataset, impl_share->sharepath); +#ifdef DEBUG + fprintf(stderr, "smb_enable_share(): dataset=%s, path=%s\n", + impl_share->dataset, impl_share->sharepath); +#endif if (!smb_available) { -// DEBUG -fprintf(stderr, " smb_enable_share(): -> !smb_available\n"); +#ifdef DEBUG + fprintf(stderr, " smb_enable_share(): -> !smb_available\n"); +#endif return SA_SYSTEM_ERR; } shareopts = FSINFO(impl_share, smb_fstype)->shareopts; if (shareopts == NULL) { /* on/off */ -// DEBUG -fprintf(stderr, " smb_enable_share(): -> SA_SYSTEM_ERR\n"); +#ifdef DEBUG + fprintf(stderr, " smb_enable_share(): -> SA_SYSTEM_ERR\n"); +#endif return SA_SYSTEM_ERR; } if (strcmp(shareopts, "off") == 0) { -// DEBUG -fprintf(stderr, " smb_enable_share(): -> off (0)\n"); +#ifdef DEBUG + fprintf(stderr, " smb_enable_share(): -> off (0)\n"); +#endif return (0); } @@ -165,22 +167,27 @@ smb_disable_share_one(const char *sharename) int rc = SA_OK; char *argv[6]; -// DEBUG -fprintf(stderr, " smb_disable_share_one()\n"); +#ifdef DEBUG + fprintf(stderr, " smb_disable_share_one()\n"); +#endif /* CMD: net -U root -S 127.0.0.1 usershare delete Test1 */ - argv[0] = "/usr/bin/net"; + if (file_exists(NET_CMD_PATH)) + return SA_SYSTEM_ERR; + argv[0] = NET_CMD_PATH; argv[1] = "usershare"; argv[2] = "delete"; argv[3] = strdup(sharename); argv[4] = NULL; -int i; -fprintf(stderr, " CMD: "); -for (i=0; argv[i] != NULL; i++) { - fprintf(stderr, "%s ", argv[i]); -} -fprintf(stderr, "\n"); +#ifdef DEBUG + int i; + fprintf(stderr, " CMD: "); + for (i=0; argv[i] != NULL; i++) { + fprintf(stderr, "%s ", argv[i]); + } + fprintf(stderr, "\n"); +#endif rc = libzfs_run_process(argv[0], argv, 0); if (rc < 0) @@ -194,8 +201,10 @@ smb_disable_share(sa_share_impl_t impl_share) { smb_share_t *shares = smb_shares; -fprintf(stderr, " smb_disable_share(): dataset=%s, path=%s\n", - impl_share->dataset, impl_share->sharepath); +#ifdef DEBUG + fprintf(stderr, " smb_disable_share(): dataset=%s, path=%s\n", + impl_share->dataset, impl_share->sharepath); +#endif while (shares != NULL) { if (strcmp(impl_share->sharepath, shares->path) == 0) @@ -215,8 +224,10 @@ smb_is_share_active(sa_share_impl_t impl_share) { smb_share_t *shares = smb_shares; -fprintf(stderr, " smb_is_share_active(): dataset=%s, path=%s\n", - impl_share->dataset, impl_share->sharepath); +#ifdef DEBUG + fprintf(stderr, " smb_is_share_active(): dataset=%s, path=%s\n", + impl_share->dataset, impl_share->sharepath); +#endif while (shares != NULL) { if (strcmp(impl_share->sharepath, shares->path) == 0) @@ -242,8 +253,9 @@ smb_update_shareopts(sa_share_impl_t impl_share, const char *resource, char *shareopts_dup; boolean_t needs_reshare = B_FALSE; char *old_shareopts; -// DEBUG -fprintf(stderr, "smb_update_shareopts()\n"); +#ifdef DEBUG + fprintf(stderr, "smb_update_shareopts()\n"); +#endif FSINFO(impl_share, smb_fstype)->active = smb_is_share_active(impl_share); @@ -274,8 +286,9 @@ fprintf(stderr, "smb_update_shareopts()\n"); static void smb_clear_shareopts(sa_share_impl_t impl_share) { -// DEBUG -fprintf(stderr, "smb_clear_shareopts()\n"); +#ifdef DEBUG + fprintf(stderr, "smb_clear_shareopts()\n"); +#endif free(FSINFO(impl_share, smb_fstype)->shareopts); FSINFO(impl_share, smb_fstype)->shareopts = NULL; } @@ -300,14 +313,16 @@ smb_retrieve_shares(void) struct dirent *directory; smb_share_t *shares, *new_shares = NULL; -// DEBUG -fprintf(stderr, " smb_retrieve_shares()\n"); +#ifdef DEBUG + fprintf(stderr, " smb_retrieve_shares()\n"); +#endif /* opendir(), stat() */ shares_dir = opendir(SHARE_DIR); if (shares_dir == NULL) { -// DEBUG -fprintf(stderr, " opendir() == NULL\n"); +#ifdef DEBUG + fprintf(stderr, " opendir() == NULL\n"); +#endif return SA_SYSTEM_ERR; } @@ -316,14 +331,16 @@ fprintf(stderr, " opendir() == NULL\n"); if ((directory->d_name[0] == '.') || (directory->d_type != 8)) /* DT_REG (regular file) if using _BSD_SOURCE */ continue; -// DEBUG -fprintf(stderr, " %s\n", directory->d_name); +#ifdef DEBUG + fprintf(stderr, " %s\n", directory->d_name); +#endif snprintf(file_path, sizeof (file_path), "%s/%s", SHARE_DIR, directory->d_name); if ((share_file_fp = fopen(file_path, "r")) == NULL) { -// DEBUG -fprintf(stderr, " fopen() == NULL\n"); +#ifdef DEBUG + fprintf(stderr, " fopen() == NULL\n"); +#endif rc = SA_SYSTEM_ERR; goto out; } @@ -343,8 +360,9 @@ fprintf(stderr, " fopen() == NULL\n"); line[strlen(line) - 1] == '\n') line[strlen(line) - 1] = '\0'; -// DEBUG -fprintf(stderr, " %s ", line); +#ifdef DEBUG + fprintf(stderr, " %s ", line); +#endif /* Split the line in two, separated by '=' */ token = strchr(line, '='); @@ -354,8 +372,9 @@ fprintf(stderr, " %s ", line); key = line; value = token + 1; *token = '\0'; -// DEBUG -fprintf(stderr, "(%s = %s)\n", key, value); +#ifdef DEBUG + fprintf(stderr, "(%s = %s)\n", key, value); +#endif dup_value = strdup(value); if (dup_value == NULL) @@ -411,8 +430,9 @@ fprintf(stderr, "(%s = %s)\n", key, value); void libshare_smb_init(void) { -// DEBUG -fprintf(stderr, "libshare_smb_init()\n"); +#ifdef DEBUG + fprintf(stderr, "libshare_smb_init()\n"); +#endif smb_available = (smb_retrieve_shares() == SA_OK); smb_fstype = register_fstype("smb", &smb_shareops); diff --git a/lib/libshare/smb.h b/lib/libshare/smb.h index 5914ec5be17f..cb9018317c6c 100644 --- a/lib/libshare/smb.h +++ b/lib/libshare/smb.h @@ -20,7 +20,6 @@ */ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011 Turbo Fredriksson . */ From 5668b98f73473dfc33a7709d1d59634e458781b0 Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Fri, 16 Dec 2011 22:46:54 +0100 Subject: [PATCH 06/15] s/file_exists()/file_is_executable()/g --- lib/libshare/libshare.c | 2 +- lib/libshare/libshare_impl.h | 2 +- lib/libshare/smb.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libshare/libshare.c b/lib/libshare/libshare.c index 42e63b869903..afa22ec1e029 100644 --- a/lib/libshare/libshare.c +++ b/lib/libshare/libshare.c @@ -57,7 +57,7 @@ static int fstypes_count; static sa_fstype_t *fstypes; int -file_exists(char *file_name) +file_is_executable(char *file_name) { if ((access(file_name, X_OK)) == 0) /* File found */ diff --git a/lib/libshare/libshare_impl.h b/lib/libshare/libshare_impl.h index c299dff19dd2..b0155540e0fc 100644 --- a/lib/libshare/libshare_impl.h +++ b/lib/libshare/libshare_impl.h @@ -68,4 +68,4 @@ typedef struct sa_handle_impl { } *sa_handle_impl_t; sa_fstype_t *register_fstype(const char *name, const sa_share_ops_t *ops); -int file_exists (char *); +int file_is_executable(char *); diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c index 22eeb5febc45..e92c885d67e4 100644 --- a/lib/libshare/smb.c +++ b/lib/libshare/smb.c @@ -90,7 +90,7 @@ smb_enable_share_one(const char *sharename, const char *sharepath) /* CMD: net -U root -S 127.0.0.1 usershare add Test1 /share/Test1 "Comment" "Everyone:F" */ snprintf(comment, sizeof (comment), "Comment: %s", sharepath); - if (file_exists(NET_CMD_PATH)) + if (file_is_executable(NET_CMD_PATH)) return SA_SYSTEM_ERR; argv[0] = NET_CMD_PATH; argv[1] = "-U"; @@ -172,7 +172,7 @@ smb_disable_share_one(const char *sharename) #endif /* CMD: net -U root -S 127.0.0.1 usershare delete Test1 */ - if (file_exists(NET_CMD_PATH)) + if (file_is_executable(NET_CMD_PATH)) return SA_SYSTEM_ERR; argv[0] = NET_CMD_PATH; argv[1] = "usershare"; From 61e78640d24b06fff93afee7974223058cd9f9c0 Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Fri, 16 Dec 2011 23:01:04 +0100 Subject: [PATCH 07/15] * Empty return fixed * s/#endif/#ifdef DEBUG/ --- lib/libshare/smb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c index e92c885d67e4..bf22dc92c151 100644 --- a/lib/libshare/smb.c +++ b/lib/libshare/smb.c @@ -74,7 +74,7 @@ smb_enable_share_one(const char *sharename, const char *sharepath) char *pos = name; if( pos == NULL ) - return; + return SA_SYSTEM_ERR; while( *pos != '\0' ) { switch( *pos ) { @@ -105,7 +105,7 @@ smb_enable_share_one(const char *sharename, const char *sharepath) argv[10] = "Everyone:F"; argv[11] = NULL; -#endif +#ifdef DEBUG int i; fprintf(stderr, " CMD: "); for (i=0; argv[i] != NULL; i++) { From bc1489fe5d1d600a6d59ca4de7bfd61c3941ceac Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Fri, 16 Dec 2011 23:29:46 +0100 Subject: [PATCH 08/15] Remove hardcoded '-U root' from 'net' command so that non-root users can add/remove shares. + Document how this can be done (samba config etc) --- lib/libshare/README_smb.txt | 9 +++++++++ lib/libshare/smb.c | 26 ++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/libshare/README_smb.txt b/lib/libshare/README_smb.txt index 4c8e754b29f5..ee9eb984c0c5 100644 --- a/lib/libshare/README_smb.txt +++ b/lib/libshare/README_smb.txt @@ -14,6 +14,15 @@ REQUIRENMENTS 3. Some configuration settings in samba: usershare max shares = 100 + usershare owner only = False + + First one is not strictly necessary if you don't have more than + 100 volumes you'd like to share. + + Second one is if you want to allow non-root users to share + volumes they do NOT own. For a non-user to be able to share + a volume, he/she will have to have write access to the /dev/zfs + device node. 4. A ZFS filesystem or more to export. diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c index bf22dc92c151..d5d4badca97f 100644 --- a/lib/libshare/smb.c +++ b/lib/libshare/smb.c @@ -61,7 +61,7 @@ int smb_retrieve_shares(void); int smb_enable_share_one(const char *sharename, const char *sharepath) { - char *argv[12], name[255], comment[255]; + char *argv[10], name[255], comment[255]; int rc; #ifdef DEBUG @@ -87,23 +87,21 @@ smb_enable_share_one(const char *sharename, const char *sharepath) ++pos; } - /* CMD: net -U root -S 127.0.0.1 usershare add Test1 /share/Test1 "Comment" "Everyone:F" */ + /* CMD: net -S 127.0.0.1 usershare add Test1 /share/Test1 "Comment" "Everyone:F" */ snprintf(comment, sizeof (comment), "Comment: %s", sharepath); if (file_is_executable(NET_CMD_PATH)) return SA_SYSTEM_ERR; argv[0] = NET_CMD_PATH; - argv[1] = "-U"; - argv[2] = "root"; - argv[3] = "-S"; - argv[4] = "127.0.0.1"; - argv[5] = "usershare"; - argv[6] = "add"; - argv[7] = name; - argv[8] = strdup(sharepath); - argv[9] = comment; - argv[10] = "Everyone:F"; - argv[11] = NULL; + argv[1] = "-S"; + argv[2] = "127.0.0.1"; + argv[3] = "usershare"; + argv[4] = "add"; + argv[5] = name; + argv[6] = strdup(sharepath); + argv[7] = comment; + argv[8] = "Everyone:F"; + argv[9] = NULL; #ifdef DEBUG int i; @@ -171,7 +169,7 @@ smb_disable_share_one(const char *sharename) fprintf(stderr, " smb_disable_share_one()\n"); #endif - /* CMD: net -U root -S 127.0.0.1 usershare delete Test1 */ + /* CMD: net -S 127.0.0.1 usershare delete Test1 */ if (file_is_executable(NET_CMD_PATH)) return SA_SYSTEM_ERR; argv[0] = NET_CMD_PATH; From 5548114056fd75e981fec2b82f4874aba4c24b36 Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Mon, 16 Jan 2012 15:25:21 +0100 Subject: [PATCH 09/15] Remove CFLAGS (optimizations) from building zvol_id - messes up the binary. --- cmd/zvol_id/Makefile.in | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/zvol_id/Makefile.in b/cmd/zvol_id/Makefile.in index d6719fdb6a31..7d5871e17cda 100644 --- a/cmd/zvol_id/Makefile.in +++ b/cmd/zvol_id/Makefile.in @@ -104,11 +104,11 @@ depcomp = $(SHELL) $(top_srcdir)/config/depcomp am__depfiles_maybe = depfiles am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) + $(CPPFLAGS) $(AM_CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CFLAGS) $(CFLAGS) + $(AM_CFLAGS) AM_V_CC = $(am__v_CC_$(V)) am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) am__v_CC_0 = @echo " CC " $@; @@ -117,7 +117,7 @@ am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) am__v_at_0 = @ CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_$(V)) am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) @@ -431,20 +431,20 @@ distclean-compile: @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< zvol_id_main.o: $(top_srcdir)/cmd/zvol_id/zvol_id_main.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT zvol_id_main.o -MD -MP -MF $(DEPDIR)/zvol_id_main.Tpo -c -o zvol_id_main.o `test -f '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c' || echo '$(srcdir)/'`$(top_srcdir)/cmd/zvol_id/zvol_id_main.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) -MT zvol_id_main.o -MD -MP -MF $(DEPDIR)/zvol_id_main.Tpo -c -o zvol_id_main.o `test -f '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c' || echo '$(srcdir)/'`$(top_srcdir)/cmd/zvol_id/zvol_id_main.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/zvol_id_main.Tpo $(DEPDIR)/zvol_id_main.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/cmd/zvol_id/zvol_id_main.c' object='zvol_id_main.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o zvol_id_main.o `test -f '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c' || echo '$(srcdir)/'`$(top_srcdir)/cmd/zvol_id/zvol_id_main.c +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) -c -o zvol_id_main.o `test -f '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c' || echo '$(srcdir)/'`$(top_srcdir)/cmd/zvol_id/zvol_id_main.c zvol_id_main.obj: $(top_srcdir)/cmd/zvol_id/zvol_id_main.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT zvol_id_main.obj -MD -MP -MF $(DEPDIR)/zvol_id_main.Tpo -c -o zvol_id_main.obj `if test -f '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; then $(CYGPATH_W) '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) -MT zvol_id_main.obj -MD -MP -MF $(DEPDIR)/zvol_id_main.Tpo -c -o zvol_id_main.obj `if test -f '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; then $(CYGPATH_W) '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/zvol_id_main.Tpo $(DEPDIR)/zvol_id_main.Po @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$(top_srcdir)/cmd/zvol_id/zvol_id_main.c' object='zvol_id_main.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o zvol_id_main.obj `if test -f '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; then $(CYGPATH_W) '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; fi` +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) -c -o zvol_id_main.obj `if test -f '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; then $(CYGPATH_W) '$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/cmd/zvol_id/zvol_id_main.c'; fi` mostlyclean-libtool: -rm -f *.lo From 8a3fb5d72f5e5152c35f5e3b27137f38b9784a5f Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Mon, 16 Jan 2012 15:24:17 +0100 Subject: [PATCH 10/15] Add --keep-version to alien to make sure the package is 'tagged' with the kernel version etc. --- Makefile.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.in b/Makefile.in index 332efc173292..aa5f1c55db74 100644 --- a/Makefile.in +++ b/Makefile.in @@ -977,7 +977,7 @@ deb-modules: deb-local rpm-modules arch=`$(RPM) -qp $${name}-$${version}.src.rpm --qf %{arch} | tail -1`; \ pkg1=$${name}-$${version}_$${release}.$${arch}.rpm; \ pkg2=$${name}-devel-$${version}_$${release}.$${arch}.rpm; \ - fakeroot $(ALIEN) --scripts --to-deb $$pkg1 $$pkg2; \ + fakeroot $(ALIEN) --keep-version --scripts --to-deb $$pkg1 $$pkg2; \ $(RM) $$pkg1 $$pkg2 deb-utils: deb-local rpm-utils @@ -988,7 +988,7 @@ deb-utils: deb-local rpm-utils pkg2=$${name}-devel-$${version}.$${arch}.rpm; \ pkg3=$${name}-test-$${version}.$${arch}.rpm; \ pkg4=$${name}-dracut-$${version}.$${arch}.rpm; \ - fakeroot $(ALIEN) --scripts --to-deb $$pkg1 $$pkg2 $$pkg3 $$pkg4; \ + fakeroot $(ALIEN) --keep-version --scripts --to-deb $$pkg1 $$pkg2 $$pkg3 $$pkg4; \ $(RM) $$pkg1 $$pkg2 $$pkg3 $$pkg4 deb: deb-modules deb-utils @@ -1008,7 +1008,7 @@ tgz-modules: tgz-local rpm-modules arch=`$(RPM) -qp $${name}-$${version}.src.rpm --qf %{arch} | tail -1`; \ pkg1=$${name}-$${version}_$${release}.$${arch}.rpm; \ pkg2=$${name}-devel-$${version}_$${release}.$${arch}.rpm; \ - fakeroot $(ALIEN) --scripts --to-tgz $$pkg1 $$pkg2; \ + fakeroot $(ALIEN) --keep-version --scripts --to-tgz $$pkg1 $$pkg2; \ $(RM) $$pkg1 $$pkg2 tgz-utils: tgz-local rpm-utils @@ -1018,7 +1018,7 @@ tgz-utils: tgz-local rpm-utils pkg1=$${name}-$${version}.$${arch}.rpm; \ pkg2=$${name}-devel-$${version}.$${arch}.rpm; \ pkg3=$${name}-test-$${version}.$${arch}.rpm; \ - fakeroot $(ALIEN) --scripts --to-tgz $$pkg1 $$pkg2 $$pkg3; \ + fakeroot $(ALIEN) --keep-version --scripts --to-tgz $$pkg1 $$pkg2 $$pkg3; \ $(RM) $$pkg1 $$pkg2 $$pkg3 tgz: tgz-modules tgz-utils From 2afd926b170a8ded8e627baa6d212aa03beef0bb Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Mon, 16 Jan 2012 17:02:52 +0100 Subject: [PATCH 11/15] Merge changes from iscsi branch. --- lib/libshare/libshare.c | 14 +++++++++++--- lib/libshare/libshare_impl.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/libshare/libshare.c b/lib/libshare/libshare.c index afa22ec1e029..77aa8e917a4f 100644 --- a/lib/libshare/libshare.c +++ b/lib/libshare/libshare.c @@ -38,6 +38,14 @@ #include "nfs.h" #include "smb.h" +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + static sa_share_impl_t find_share(sa_handle_impl_t handle, const char *sharepath); static sa_share_impl_t alloc_share(const char *sharepath); @@ -56,13 +64,13 @@ static int update_zfs_shares(sa_handle_impl_t impl_handle, const char *proto); static int fstypes_count; static sa_fstype_t *fstypes; -int +boolean_t file_is_executable(char *file_name) { if ((access(file_name, X_OK)) == 0) /* File found */ - return SA_OK; - return SA_NO_SUCH_PATH; + return TRUE; + return FALSE; } sa_fstype_t * diff --git a/lib/libshare/libshare_impl.h b/lib/libshare/libshare_impl.h index b0155540e0fc..3f7413115341 100644 --- a/lib/libshare/libshare_impl.h +++ b/lib/libshare/libshare_impl.h @@ -68,4 +68,4 @@ typedef struct sa_handle_impl { } *sa_handle_impl_t; sa_fstype_t *register_fstype(const char *name, const sa_share_ops_t *ops); -int file_is_executable(char *); +boolean_t file_is_executable(char *); From 4deb5661a579827927a123fec5140bfc759ee1e6 Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Mon, 16 Jan 2012 17:03:42 +0100 Subject: [PATCH 12/15] Fix some comments from Richard Laager + Define and use SMB_NAME_MAX for name and comment. + Use PATH_MAX with path. + Possible memory leak with strncpy (add NUL at end). + file_is_executable() now return bool (TRUE/FALSE). + Use stat() instead of readdir()->d_type/DT_REG. + Attempt to replace my trim trailing new-lines. Didn't work so revert to my code (new code need more testing). --- lib/libshare/smb.c | 57 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c index d5d4badca97f..316d264d0ecb 100644 --- a/lib/libshare/smb.c +++ b/lib/libshare/smb.c @@ -35,16 +35,21 @@ #include #include #include +#include +#include #include #include #include "libshare_impl.h" #include "smb.h" +/* The maximum SMB share name seems to be 254 characters, though good references are hard to find. */ +#define SMB_NAME_MAX 255 + typedef struct smb_share_s { - char name[255]; /* Share name */ - char path[255]; /* Share path */ - char comment[255]; /* Share's comment */ - boolean_t guest_ok; /* 'y' or 'n' */ + char name[SMB_NAME_MAX]; /* Share name */ + char path[PATH_MAX]; /* Share path */ + char comment[255]; /* Share's comment */ + boolean_t guest_ok; /* 'y' or 'n' */ struct smb_share_s *next; } smb_share_t; @@ -61,7 +66,8 @@ int smb_retrieve_shares(void); int smb_enable_share_one(const char *sharename, const char *sharepath) { - char *argv[10], name[255], comment[255]; + char *argv[10]; + char name[SMB_NAME_MAX], comment[SMB_NAME_MAX]; int rc; #ifdef DEBUG @@ -71,6 +77,7 @@ smb_enable_share_one(const char *sharename, const char *sharepath) /* Support ZFS share name regexp '[[:alnum:]_-.: ]' */ strncpy(name, sharename, sizeof(name)); + name [sizeof(name)-1] = '\0'; char *pos = name; if( pos == NULL ) @@ -90,15 +97,17 @@ smb_enable_share_one(const char *sharename, const char *sharepath) /* CMD: net -S 127.0.0.1 usershare add Test1 /share/Test1 "Comment" "Everyone:F" */ snprintf(comment, sizeof (comment), "Comment: %s", sharepath); - if (file_is_executable(NET_CMD_PATH)) + if (!file_is_executable(NET_CMD_PATH)) { + fprintf(stderr, "ERROR: %s: Does not exists or is not executable.\n", NET_CMD_PATH); return SA_SYSTEM_ERR; + } argv[0] = NET_CMD_PATH; argv[1] = "-S"; argv[2] = "127.0.0.1"; argv[3] = "usershare"; argv[4] = "add"; argv[5] = name; - argv[6] = strdup(sharepath); + argv[6] = sharepath; argv[7] = comment; argv[8] = "Everyone:F"; argv[9] = NULL; @@ -170,8 +179,10 @@ smb_disable_share_one(const char *sharename) #endif /* CMD: net -S 127.0.0.1 usershare delete Test1 */ - if (file_is_executable(NET_CMD_PATH)) + if (!file_is_executable(NET_CMD_PATH)) { + fprintf(stderr, "ERROR: %s: Does not exists or is not executable.\n", NET_CMD_PATH); return SA_SYSTEM_ERR; + } argv[0] = NET_CMD_PATH; argv[1] = "usershare"; argv[2] = "delete"; @@ -304,11 +315,12 @@ int smb_retrieve_shares(void) { int rc = SA_OK; - char file_path[255], line[512], *token, *key, *value, *dup_value; + char file_path[PATH_MAX], line[512], *token, *key, *value, *dup_value, *c; char *path = NULL, *comment = NULL, *name = NULL, *guest_ok = NULL; DIR *shares_dir; FILE *share_file_fp; struct dirent *directory; + struct stat eStat; smb_share_t *shares, *new_shares = NULL; #ifdef DEBUG @@ -326,8 +338,13 @@ smb_retrieve_shares(void) /* Go through the directory, looking for shares */ while ((directory = readdir(shares_dir))) { - if ((directory->d_name[0] == '.') || - (directory->d_type != 8)) /* DT_REG (regular file) if using _BSD_SOURCE */ + if (stat(directory->d_name, &eStat) == ENOMEM) { + rc = SA_NO_MEMORY; + goto out; + } + + if ((directory->d_name[0] == '.') || + !S_ISREG(eStat.st_mode)) continue; #ifdef DEBUG fprintf(stderr, " %s\n", directory->d_name); @@ -357,6 +374,12 @@ smb_retrieve_shares(void) while (line[strlen(line) - 1] == '\r' || line[strlen(line) - 1] == '\n') line[strlen(line) - 1] = '\0'; +// for (c = line; *c; c++) { +// if (*c == '\r' || *c == '\n') { +// c = '\0'; +// break; +// } +// } #ifdef DEBUG fprintf(stderr, " %s ", line); @@ -375,8 +398,10 @@ smb_retrieve_shares(void) #endif dup_value = strdup(value); - if (dup_value == NULL) - exit(SA_NO_MEMORY); + if (dup_value == NULL) { + rc = SA_NO_MEMORY; + goto out; + } if (strcmp(key, "path") == 0) path = dup_value; @@ -395,8 +420,14 @@ smb_retrieve_shares(void) } strncpy(shares->name, name, sizeof (shares->name)); + shares->name [sizeof(shares->name)-1] = '\0'; + strncpy(shares->path, path, sizeof (shares->path)); + shares->path [sizeof(shares->path)-1] = '\0'; + strncpy(shares->comment, comment, sizeof (shares->comment)); + shares->comment [sizeof(shares->comment)-1] = '\0'; + shares->guest_ok = atoi(guest_ok); shares->next = new_shares; From 28598facf9a3a6dda9abe7b18e6d1141d271c523 Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Mon, 16 Jan 2012 17:33:54 +0100 Subject: [PATCH 13/15] Fix stat/S_ISREG. --- lib/libshare/smb.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c index 316d264d0ecb..48af7ec691c4 100644 --- a/lib/libshare/smb.c +++ b/lib/libshare/smb.c @@ -338,20 +338,26 @@ smb_retrieve_shares(void) /* Go through the directory, looking for shares */ while ((directory = readdir(shares_dir))) { - if (stat(directory->d_name, &eStat) == ENOMEM) { - rc = SA_NO_MEMORY; + if (directory->d_name[0] == '.') + continue; + + snprintf(file_path, sizeof (file_path), + "%s/%s", SHARE_DIR, directory->d_name); + + if (stat(file_path, &eStat) == -1) { + fprintf(stderr, "ERROR: stat()\n"); + + rc = SA_SYSTEM_ERR; goto out; } - if ((directory->d_name[0] == '.') || - !S_ISREG(eStat.st_mode)) + if (!S_ISREG(eStat.st_mode)) continue; + #ifdef DEBUG fprintf(stderr, " %s\n", directory->d_name); #endif - snprintf(file_path, sizeof (file_path), - "%s/%s", SHARE_DIR, directory->d_name); if ((share_file_fp = fopen(file_path, "r")) == NULL) { #ifdef DEBUG fprintf(stderr, " fopen() == NULL\n"); From 9619cf2324f0aa988646e4cd4b1faf389355419e Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Tue, 17 Jan 2012 07:13:22 +0100 Subject: [PATCH 14/15] Wrong merge resolve. --- config/kernel.m4 | 4 - configure | 852 +++++++---------------------------------- module/zfs/zpl_super.c | 126 +----- 3 files changed, 154 insertions(+), 828 deletions(-) diff --git a/config/kernel.m4 b/config/kernel.m4 index 45e9b149aa83..63a3237ec8b7 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -34,16 +34,12 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [ ZFS_AC_KERNEL_XATTR_HANDLER_SET ZFS_AC_KERNEL_FSYNC ZFS_AC_KERNEL_EVICT_INODE - ZFS_AC_KERNEL_NR_CACHED_OBJECTS - ZFS_AC_KERNEL_FREE_CACHED_OBJECTS ZFS_AC_KERNEL_INSERT_INODE_LOCKED ZFS_AC_KERNEL_D_OBTAIN_ALIAS ZFS_AC_KERNEL_CHECK_DISK_SIZE_CHANGE ZFS_AC_KERNEL_TRUNCATE_SETSIZE ZFS_AC_KERNEL_6ARGS_SECURITY_INODE_INIT_SECURITY - ZFS_AC_KERNEL_CALLBACK_SECURITY_INODE_INIT_SECURITY ZFS_AC_KERNEL_MOUNT_NODEV - ZFS_AC_KERNEL_SHRINK ZFS_AC_KERNEL_BDI ZFS_AC_KERNEL_BDI_SETUP_AND_REGISTER ZFS_AC_KERNEL_SET_NLINK diff --git a/configure b/configure index 4659124f101a..d6f405bbbd09 100755 --- a/configure +++ b/configure @@ -813,6 +813,10 @@ LINUX NO_UNUSED_BUT_SET_VARIABLE ZFS_CONFIG TARGET_ASM_DIR +DEFAULT_INIT_SCRIPT +DEFAULT_INIT_DIR +DEFAULT_PACKAGE +VENDOR MAKEPKG_VERSION MAKEPKG HAVE_MAKEPKG @@ -834,10 +838,6 @@ HAVE_RPMBUILD RPM_VERSION RPM HAVE_RPM -DEFAULT_INIT_SCRIPT -DEFAULT_INIT_DIR -DEFAULT_PACKAGE -VENDOR am__fastdepCCAS_FALSE am__fastdepCCAS_TRUE CCASDEPMODE @@ -11671,83 +11671,6 @@ $as_echo "$ZFS_META_LICENSE" >&6; } - { $as_echo "$as_me:$LINENO: checking linux distribution" >&5 -$as_echo_n "checking linux distribution... " >&6; } - if test -f /etc/redhat-release ; then - VENDOR=redhat ; - elif test -f /etc/fedora-release ; then - VENDOR=fedora ; - elif test -f /etc/gentoo-release ; then - VENDOR=gentoo ; - elif test -f /etc/debian_version ; then - VENDOR=debian ; - elif test -f /etc/SuSE-release ; then - VENDOR=sles ; - elif test -f /etc/slackware-version ; then - VENDOR=slackware ; - elif test -f /etc/arch-release ; then - VENDOR=arch ; - elif test -f /etc/lsb-release ; then - VENDOR=ubuntu ; - elif test -f /etc/lunar.release ; then - VENDOR=lunar ; - else - VENDOR= ; - fi - { $as_echo "$as_me:$LINENO: result: $VENDOR" >&5 -$as_echo "$VENDOR" >&6; } - - - { $as_echo "$as_me:$LINENO: checking default package type" >&5 -$as_echo_n "checking default package type... " >&6; } - case "$VENDOR" in - redhat) DEFAULT_PACKAGE=rpm ;; - fedora) DEFAULT_PACKAGE=rpm ;; - ubuntu) DEFAULT_PACKAGE=deb ;; - debian) DEFAULT_PACKAGE=deb ;; - sles) DEFAULT_PACKAGE=rpm ;; - slackware) DEFAULT_PACKAGE=tgz ;; - gentoo) DEFAULT_PACKAGE=tgz ;; - lunar) DEFAULT_PACKAGE=tgz ;; - arch) DEFAULT_PACKAGE=arch;; - *) DEFAULT_PACKAGE=rpm ;; - esac - - { $as_echo "$as_me:$LINENO: result: $DEFAULT_PACKAGE" >&5 -$as_echo "$DEFAULT_PACKAGE" >&6; } - - - { $as_echo "$as_me:$LINENO: checking default init directory" >&5 -$as_echo_n "checking default init directory... " >&6; } - case "$VENDOR" in - arch) DEFAULT_INIT_DIR=$sysconfdir/rc.d ;; - *) DEFAULT_INIT_DIR=$sysconfdir/init.d ;; - esac - - { $as_echo "$as_me:$LINENO: result: $DEFAULT_INIT_DIR" >&5 -$as_echo "$DEFAULT_INIT_DIR" >&6; } - - - { $as_echo "$as_me:$LINENO: checking default init script type" >&5 -$as_echo_n "checking default init script type... " >&6; } - case "$VENDOR" in - redhat) DEFAULT_INIT_SCRIPT=redhat ;; - fedora) DEFAULT_INIT_SCRIPT=fedora ;; - ubuntu) DEFAULT_INIT_SCRIPT=lsb ;; - debian) DEFAULT_INIT_SCRIPT=lsb ;; - sles) DEFAULT_INIT_SCRIPT=lsb ;; - slackware) DEFAULT_INIT_SCRIPT=lsb ;; - gentoo) DEFAULT_INIT_SCRIPT=gentoo ;; - lunar) DEFAULT_INIT_SCRIPT=lunar ;; - arch) DEFAULT_INIT_SCRIPT=arch ;; - *) DEFAULT_INIT_SCRIPT=lsb ;; - esac - - { $as_echo "$as_me:$LINENO: result: $DEFAULT_INIT_SCRIPT" >&5 -$as_echo "$DEFAULT_INIT_SCRIPT" >&6; } - - - RPM=rpm RPMBUILD=rpmbuild @@ -11870,8 +11793,6 @@ fi - if test "$VENDOR" = "arch"; then - PACMAN=pacman MAKEPKG=makepkg @@ -11923,7 +11844,82 @@ fi -fi + + { $as_echo "$as_me:$LINENO: checking linux distribution" >&5 +$as_echo_n "checking linux distribution... " >&6; } + if test -f /etc/redhat-release ; then + VENDOR=redhat ; + elif test -f /etc/fedora-release ; then + VENDOR=fedora ; + elif test -f /etc/gentoo-release ; then + VENDOR=gentoo ; + elif test -f /etc/debian_version ; then + VENDOR=debian ; + elif test -f /etc/SuSE-release ; then + VENDOR=sles ; + elif test -f /etc/slackware-version ; then + VENDOR=slackware ; + elif test -f /etc/arch-release ; then + VENDOR=arch ; + elif test -f /etc/lsb-release ; then + VENDOR=ubuntu ; + elif test -f /etc/lunar.release ; then + VENDOR=lunar ; + else + VENDOR= ; + fi + { $as_echo "$as_me:$LINENO: result: $VENDOR" >&5 +$as_echo "$VENDOR" >&6; } + + + { $as_echo "$as_me:$LINENO: checking default package type" >&5 +$as_echo_n "checking default package type... " >&6; } + case "$VENDOR" in + redhat) DEFAULT_PACKAGE=rpm ;; + fedora) DEFAULT_PACKAGE=rpm ;; + ubuntu) DEFAULT_PACKAGE=deb ;; + debian) DEFAULT_PACKAGE=deb ;; + sles) DEFAULT_PACKAGE=rpm ;; + slackware) DEFAULT_PACKAGE=tgz ;; + gentoo) DEFAULT_PACKAGE=tgz ;; + lunar) DEFAULT_PACKAGE=tgz ;; + arch) DEFAULT_PACKAGE=arch;; + *) DEFAULT_PACKAGE=rpm ;; + esac + + { $as_echo "$as_me:$LINENO: result: $DEFAULT_PACKAGE" >&5 +$as_echo "$DEFAULT_PACKAGE" >&6; } + + + { $as_echo "$as_me:$LINENO: checking default init directory" >&5 +$as_echo_n "checking default init directory... " >&6; } + case "$VENDOR" in + arch) DEFAULT_INIT_DIR=$sysconfdir/rc.d ;; + *) DEFAULT_INIT_DIR=$sysconfdir/init.d ;; + esac + + { $as_echo "$as_me:$LINENO: result: $DEFAULT_INIT_DIR" >&5 +$as_echo "$DEFAULT_INIT_DIR" >&6; } + + + { $as_echo "$as_me:$LINENO: checking default init script type" >&5 +$as_echo_n "checking default init script type... " >&6; } + case "$VENDOR" in + redhat) DEFAULT_INIT_SCRIPT=redhat ;; + fedora) DEFAULT_INIT_SCRIPT=fedora ;; + ubuntu) DEFAULT_INIT_SCRIPT=lsb ;; + debian) DEFAULT_INIT_SCRIPT=lsb ;; + sles) DEFAULT_INIT_SCRIPT=lsb ;; + slackware) DEFAULT_INIT_SCRIPT=lsb ;; + gentoo) DEFAULT_INIT_SCRIPT=gentoo ;; + lunar) DEFAULT_INIT_SCRIPT=lunar ;; + arch) DEFAULT_INIT_SCRIPT=arch ;; + *) DEFAULT_INIT_SCRIPT=lsb ;; + esac + + { $as_echo "$as_me:$LINENO: result: $DEFAULT_INIT_SCRIPT" >&5 +$as_echo "$DEFAULT_INIT_SCRIPT" >&6; } + @@ -14778,226 +14774,88 @@ fi - { $as_echo "$as_me:$LINENO: checking whether sops->nr_cached_objects() exists" >&5 -$as_echo_n "checking whether sops->nr_cached_objects() exists... " >&6; } + { $as_echo "$as_me:$LINENO: checking whether symbol insert_inode_locked is exported" >&5 +$as_echo_n "checking whether symbol insert_inode_locked is exported... " >&6; } + grep -q -E '[[:space:]]insert_inode_locked[[:space:]]' \ + $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null + rc=$? + if test $rc -ne 0; then + export=0 + for file in fs/inode.c; do + grep -q -E "EXPORT_SYMBOL.*(insert_inode_locked)" "$LINUX/$file" 2>/dev/null + rc=$? + if test $rc -eq 0; then -cat confdefs.h - <<_ACEOF >conftest.c -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ + export=1 + break; +fi - #include + done + if test $export -eq 0; then -int -main (void) -{ + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } - int (*nr_cached_objects)(struct super_block *) - __attribute__ ((unused)) = NULL; - struct super_operations sops __attribute__ ((unused)) = { - .nr_cached_objects = nr_cached_objects, - }; - ; - return 0; -} +else + + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } +cat >>confdefs.h <<\_ACEOF +#define HAVE_INSERT_INODE_LOCKED 1 _ACEOF - rm -Rf build && mkdir -p build - echo "obj-m := conftest.o" >build/Makefile - if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then +fi + + +else { $as_echo "$as_me:$LINENO: result: yes" >&5 $as_echo "yes" >&6; } cat >>confdefs.h <<\_ACEOF -#define HAVE_NR_CACHED_OBJECTS 1 +#define HAVE_INSERT_INODE_LOCKED 1 _ACEOF -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 +fi - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi + { $as_echo "$as_me:$LINENO: checking whether symbol d_obtain_alias is exported" >&5 +$as_echo_n "checking whether symbol d_obtain_alias is exported... " >&6; } + grep -q -E '[[:space:]]d_obtain_alias[[:space:]]' \ + $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null + rc=$? + if test $rc -ne 0; then - rm -Rf build + export=0 + for file in fs/dcache.c; do + grep -q -E "EXPORT_SYMBOL.*(d_obtain_alias)" "$LINUX/$file" 2>/dev/null + rc=$? + if test $rc -eq 0; then + export=1 + break; +fi + done + if test $export -eq 0; then - { $as_echo "$as_me:$LINENO: checking whether sops->free_cached_objects() exists" >&5 -$as_echo_n "checking whether sops->free_cached_objects() exists... " >&6; } + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } -cat confdefs.h - <<_ACEOF >conftest.c -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ +else - - #include - -int -main (void) -{ - - void (*free_cached_objects)(struct super_block *, int) - __attribute__ ((unused)) = NULL; - struct super_operations sops __attribute__ ((unused)) = { - .free_cached_objects = free_cached_objects, - }; - - ; - return 0; -} - -_ACEOF - - - rm -Rf build && mkdir -p build - echo "obj-m := conftest.o" >build/Makefile - if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } - -cat >>confdefs.h <<\_ACEOF -#define HAVE_FREE_CACHED_OBJECTS 1 -_ACEOF - - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } - - - -fi - - rm -Rf build - - - - - { $as_echo "$as_me:$LINENO: checking whether symbol insert_inode_locked is exported" >&5 -$as_echo_n "checking whether symbol insert_inode_locked is exported... " >&6; } - grep -q -E '[[:space:]]insert_inode_locked[[:space:]]' \ - $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null - rc=$? - if test $rc -ne 0; then - - export=0 - for file in fs/inode.c; do - grep -q -E "EXPORT_SYMBOL.*(insert_inode_locked)" "$LINUX/$file" 2>/dev/null - rc=$? - if test $rc -eq 0; then - - export=1 - break; - -fi - - done - if test $export -eq 0; then - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } - - -else - - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } - -cat >>confdefs.h <<\_ACEOF -#define HAVE_INSERT_INODE_LOCKED 1 -_ACEOF - - -fi - - -else - - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } - -cat >>confdefs.h <<\_ACEOF -#define HAVE_INSERT_INODE_LOCKED 1 -_ACEOF - - -fi - - - - - { $as_echo "$as_me:$LINENO: checking whether symbol d_obtain_alias is exported" >&5 -$as_echo_n "checking whether symbol d_obtain_alias is exported... " >&6; } - grep -q -E '[[:space:]]d_obtain_alias[[:space:]]' \ - $LINUX_OBJ/$LINUX_SYMBOLS 2>/dev/null - rc=$? - if test $rc -ne 0; then - - export=0 - for file in fs/dcache.c; do - grep -q -E "EXPORT_SYMBOL.*(d_obtain_alias)" "$LINUX/$file" 2>/dev/null - rc=$? - if test $rc -eq 0; then - - export=1 - break; - -fi - - done - if test $export -eq 0; then - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } - - -else - - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } cat >>confdefs.h <<\_ACEOF #define HAVE_D_OBTAIN_ALIAS 1 @@ -15148,14 +15006,7 @@ int main (void) { - struct inode *ip __attribute__ ((unused)) = NULL; - struct inode *dip __attribute__ ((unused)) = NULL; - const struct qstr *str __attribute__ ((unused)) = NULL; - char *name __attribute__ ((unused)) = NULL; - void *value __attribute__ ((unused)) = NULL; - size_t len __attribute__ ((unused)) = 0; - - security_inode_init_security(ip, dip, str, &name, &value, &len); + security_inode_init_security(NULL,NULL,NULL,NULL,NULL,NULL); ; return 0; @@ -15195,79 +15046,6 @@ $as_echo "no" >&6; } -fi - - rm -Rf build - - - EXTRA_KCFLAGS="$tmp_flags" - - - { $as_echo "$as_me:$LINENO: checking whether security_inode_init_security wants callback" >&5 -$as_echo_n "checking whether security_inode_init_security wants callback... " >&6; } - tmp_flags="$EXTRA_KCFLAGS" - EXTRA_KCFLAGS="-Werror" - - -cat confdefs.h - <<_ACEOF >conftest.c -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - - #include - -int -main (void) -{ - - struct inode *ip __attribute__ ((unused)) = NULL; - struct inode *dip __attribute__ ((unused)) = NULL; - const struct qstr *str __attribute__ ((unused)) = NULL; - initxattrs func __attribute__ ((unused)) = NULL; - - security_inode_init_security(ip, dip, str, func, NULL); - - ; - return 0; -} - -_ACEOF - - - rm -Rf build && mkdir -p build - echo "obj-m := conftest.o" >build/Makefile - if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } - -cat >>confdefs.h <<\_ACEOF -#define HAVE_CALLBACK_SECURITY_INODE_INIT_SECURITY 1 -_ACEOF - - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } - - - fi rm -Rf build @@ -15324,79 +15102,7 @@ cat >>confdefs.h <<\_ACEOF _ACEOF -fi - - - - - { $as_echo "$as_me:$LINENO: checking whether super_block has s_shrink" >&5 -$as_echo_n "checking whether super_block has s_shrink... " >&6; } - - -cat confdefs.h - <<_ACEOF >conftest.c -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - - #include - -int -main (void) -{ - - int (*shrink)(struct shrinker *, struct shrink_control *sc) - __attribute__ ((unused)) = NULL; - struct super_block sb __attribute__ ((unused)) = { - .s_shrink.shrink = shrink, - .s_shrink.seeks = DEFAULT_SEEKS, - .s_shrink.batch = 0, - }; - - ; - return 0; -} - -_ACEOF - - - rm -Rf build && mkdir -p build - echo "obj-m := conftest.o" >build/Makefile - if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SHRINK 1 -_ACEOF - - - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } - - - -fi - - rm -Rf build +fi @@ -19905,144 +19611,6 @@ fi - { $as_echo "$as_me:$LINENO: checking whether sops->nr_cached_objects() exists" >&5 -$as_echo_n "checking whether sops->nr_cached_objects() exists... " >&6; } - - -cat confdefs.h - <<_ACEOF >conftest.c -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - - #include - -int -main (void) -{ - - int (*nr_cached_objects)(struct super_block *) - __attribute__ ((unused)) = NULL; - struct super_operations sops __attribute__ ((unused)) = { - .nr_cached_objects = nr_cached_objects, - }; - - ; - return 0; -} - -_ACEOF - - - rm -Rf build && mkdir -p build - echo "obj-m := conftest.o" >build/Makefile - if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } - -cat >>confdefs.h <<\_ACEOF -#define HAVE_NR_CACHED_OBJECTS 1 -_ACEOF - - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } - - - -fi - - rm -Rf build - - - - - { $as_echo "$as_me:$LINENO: checking whether sops->free_cached_objects() exists" >&5 -$as_echo_n "checking whether sops->free_cached_objects() exists... " >&6; } - - -cat confdefs.h - <<_ACEOF >conftest.c -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - - #include - -int -main (void) -{ - - void (*free_cached_objects)(struct super_block *, int) - __attribute__ ((unused)) = NULL; - struct super_operations sops __attribute__ ((unused)) = { - .free_cached_objects = free_cached_objects, - }; - - ; - return 0; -} - -_ACEOF - - - rm -Rf build && mkdir -p build - echo "obj-m := conftest.o" >build/Makefile - if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } - -cat >>confdefs.h <<\_ACEOF -#define HAVE_FREE_CACHED_OBJECTS 1 -_ACEOF - - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } - - - -fi - - rm -Rf build - - - - { $as_echo "$as_me:$LINENO: checking whether symbol insert_inode_locked is exported" >&5 $as_echo_n "checking whether symbol insert_inode_locked is exported... " >&6; } grep -q -E '[[:space:]]insert_inode_locked[[:space:]]' \ @@ -20275,14 +19843,7 @@ int main (void) { - struct inode *ip __attribute__ ((unused)) = NULL; - struct inode *dip __attribute__ ((unused)) = NULL; - const struct qstr *str __attribute__ ((unused)) = NULL; - char *name __attribute__ ((unused)) = NULL; - void *value __attribute__ ((unused)) = NULL; - size_t len __attribute__ ((unused)) = 0; - - security_inode_init_security(ip, dip, str, &name, &value, &len); + security_inode_init_security(NULL,NULL,NULL,NULL,NULL,NULL); ; return 0; @@ -20322,79 +19883,6 @@ $as_echo "no" >&6; } -fi - - rm -Rf build - - - EXTRA_KCFLAGS="$tmp_flags" - - - { $as_echo "$as_me:$LINENO: checking whether security_inode_init_security wants callback" >&5 -$as_echo_n "checking whether security_inode_init_security wants callback... " >&6; } - tmp_flags="$EXTRA_KCFLAGS" - EXTRA_KCFLAGS="-Werror" - - -cat confdefs.h - <<_ACEOF >conftest.c -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - - #include - -int -main (void) -{ - - struct inode *ip __attribute__ ((unused)) = NULL; - struct inode *dip __attribute__ ((unused)) = NULL; - const struct qstr *str __attribute__ ((unused)) = NULL; - initxattrs func __attribute__ ((unused)) = NULL; - - security_inode_init_security(ip, dip, str, func, NULL); - - ; - return 0; -} - -_ACEOF - - - rm -Rf build && mkdir -p build - echo "obj-m := conftest.o" >build/Makefile - if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } - -cat >>confdefs.h <<\_ACEOF -#define HAVE_CALLBACK_SECURITY_INODE_INIT_SECURITY 1 -_ACEOF - - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } - - - fi rm -Rf build @@ -20456,78 +19944,6 @@ fi - { $as_echo "$as_me:$LINENO: checking whether super_block has s_shrink" >&5 -$as_echo_n "checking whether super_block has s_shrink... " >&6; } - - -cat confdefs.h - <<_ACEOF >conftest.c -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - - #include - -int -main (void) -{ - - int (*shrink)(struct shrinker *, struct shrink_control *sc) - __attribute__ ((unused)) = NULL; - struct super_block sb __attribute__ ((unused)) = { - .s_shrink.shrink = shrink, - .s_shrink.seeks = DEFAULT_SEEKS, - .s_shrink.batch = 0, - }; - - ; - return 0; -} - -_ACEOF - - - rm -Rf build && mkdir -p build - echo "obj-m := conftest.o" >build/Makefile - if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SHRINK 1 -_ACEOF - - - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } - - - -fi - - rm -Rf build - - - - { $as_echo "$as_me:$LINENO: checking whether super_block has s_bdi" >&5 $as_echo_n "checking whether super_block has s_bdi... " >&6; } diff --git a/module/zfs/zpl_super.c b/module/zfs/zpl_super.c index 3abb26a9e418..650e9c0d3791 100644 --- a/module/zfs/zpl_super.c +++ b/module/zfs/zpl_super.c @@ -199,120 +199,34 @@ zpl_kill_sb(struct super_block *sb) kill_anon_super(sb); } -#ifdef HAVE_SHRINK -/* - * Linux 3.1 - 3.x API - * - * The Linux 3.1 API introduced per-sb cache shrinkers to replace the - * global ones. This allows us a mechanism to cleanly target a specific - * zfs file system when the dnode and inode caches grow too large. - * - * In addition, the 3.0 kernel added the iterate_supers_type() helper - * function which is used to safely walk all of the zfs file systems. - */ -static void -zpl_prune_sb(struct super_block *sb, void *arg) -{ - int objects = 0; - int error; - - error = -zfs_sb_prune(sb, *(unsigned long *)arg, &objects); - ASSERT3S(error, <=, 0); - - return; -} - -void -zpl_prune_sbs(int64_t bytes_to_scan, void *private) -{ - unsigned long nr_to_scan = (bytes_to_scan / sizeof(znode_t)); - - iterate_supers_type(&zpl_fs_type, zpl_prune_sb, &nr_to_scan); - kmem_reap(); -} -#else -/* - * Linux 2.6.x - 3.0 API - * - * These are best effort interfaces are provided by the SPL to induce - * the Linux VM subsystem to reclaim a fraction of the both dnode and - * inode caches. Ideally, we want to just target the zfs file systems - * however our only option is to reclaim from them all. - */ -void -zpl_prune_sbs(int64_t bytes_to_scan, void *private) -{ - unsigned long nr_to_scan = (bytes_to_scan / sizeof(znode_t)); - - shrink_dcache_memory(nr_to_scan, GFP_KERNEL); - shrink_icache_memory(nr_to_scan, GFP_KERNEL); - kmem_reap(); -} -#endif /* HAVE_SHRINK */ - -#ifdef HAVE_NR_CACHED_OBJECTS -static int -zpl_nr_cached_objects(struct super_block *sb) -{ - zfs_sb_t *zsb = sb->s_fs_info; - int nr; - - mutex_enter(&zsb->z_znodes_lock); - nr = zsb->z_nr_znodes; - mutex_exit(&zsb->z_znodes_lock); - - return (nr); -} -#endif /* HAVE_NR_CACHED_OBJECTS */ - -#ifdef HAVE_FREE_CACHED_OBJECTS -/* - * Attempt to evict some meta data from the cache. The ARC operates in - * terms of bytes while the Linux VFS uses objects. Now because this is - * just a best effort eviction and the exact values aren't critical so we - * extrapolate from an object count to a byte size using the znode_t size. - */ -static void -zpl_free_cached_objects(struct super_block *sb, int nr_to_scan) -{ - arc_adjust_meta(nr_to_scan * sizeof(znode_t), B_FALSE); -} -#endif /* HAVE_FREE_CACHED_OBJECTS */ - const struct super_operations zpl_super_operations = { - .alloc_inode = zpl_inode_alloc, - .destroy_inode = zpl_inode_destroy, - .dirty_inode = NULL, - .write_inode = NULL, - .drop_inode = NULL, + .alloc_inode = zpl_inode_alloc, + .destroy_inode = zpl_inode_destroy, + .dirty_inode = NULL, + .write_inode = NULL, + .drop_inode = NULL, #ifdef HAVE_EVICT_INODE - .evict_inode = zpl_evict_inode, + .evict_inode = zpl_evict_inode, #else - .clear_inode = zpl_clear_inode, - .delete_inode = zpl_inode_delete, + .clear_inode = zpl_clear_inode, + .delete_inode = zpl_inode_delete, #endif /* HAVE_EVICT_INODE */ - .put_super = zpl_put_super, - .write_super = NULL, - .sync_fs = zpl_sync_fs, - .statfs = zpl_statfs, - .remount_fs = zpl_remount_fs, - .show_options = zpl_show_options, - .show_stats = NULL, -#ifdef HAVE_NR_CACHED_OBJECTS - .nr_cached_objects = zpl_nr_cached_objects, -#endif /* HAVE_NR_CACHED_OBJECTS */ -#ifdef HAVE_FREE_CACHED_OBJECTS - .free_cached_objects = zpl_free_cached_objects, -#endif /* HAVE_FREE_CACHED_OBJECTS */ + .put_super = zpl_put_super, + .write_super = NULL, + .sync_fs = zpl_sync_fs, + .statfs = zpl_statfs, + .remount_fs = zpl_remount_fs, + .show_options = zpl_show_options, + .show_stats = NULL, }; struct file_system_type zpl_fs_type = { - .owner = THIS_MODULE, - .name = ZFS_DRIVER, + .owner = THIS_MODULE, + .name = ZFS_DRIVER, #ifdef HAVE_MOUNT_NODEV - .mount = zpl_mount, + .mount = zpl_mount, #else - .get_sb = zpl_get_sb, + .get_sb = zpl_get_sb, #endif /* HAVE_MOUNT_NODEV */ - .kill_sb = zpl_kill_sb, + .kill_sb = zpl_kill_sb, }; From 6045593566feeae7c01b1309db38c83d183afbdc Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Tue, 17 Jan 2012 07:27:10 +0100 Subject: [PATCH 15/15] Debugging changes. --- lib/libshare/smb.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/libshare/smb.c b/lib/libshare/smb.c index 48af7ec691c4..2fe7bffdf17e 100644 --- a/lib/libshare/smb.c +++ b/lib/libshare/smb.c @@ -330,9 +330,7 @@ smb_retrieve_shares(void) /* opendir(), stat() */ shares_dir = opendir(SHARE_DIR); if (shares_dir == NULL) { -#ifdef DEBUG - fprintf(stderr, " opendir() == NULL\n"); -#endif + fprintf(stderr, "ERROR: smb.c:smb_retrieve_shares()/opendir()\n"); return SA_SYSTEM_ERR; } @@ -341,11 +339,14 @@ smb_retrieve_shares(void) if (directory->d_name[0] == '.') continue; +#ifdef DEBUG + fprintf(stderr, " %s\n", directory->d_name); +#endif snprintf(file_path, sizeof (file_path), "%s/%s", SHARE_DIR, directory->d_name); if (stat(file_path, &eStat) == -1) { - fprintf(stderr, "ERROR: stat()\n"); + fprintf(stderr, "ERROR: smb.c:smb_retrieve_shares()/stat()\n"); rc = SA_SYSTEM_ERR; goto out; @@ -354,14 +355,9 @@ smb_retrieve_shares(void) if (!S_ISREG(eStat.st_mode)) continue; -#ifdef DEBUG - fprintf(stderr, " %s\n", directory->d_name); -#endif - if ((share_file_fp = fopen(file_path, "r")) == NULL) { -#ifdef DEBUG - fprintf(stderr, " fopen() == NULL\n"); -#endif + fprintf(stderr, "ERROR: smb.c:smb_retrieve_shares()/fopen()\n"); + rc = SA_SYSTEM_ERR; goto out; } @@ -399,9 +395,6 @@ smb_retrieve_shares(void) key = line; value = token + 1; *token = '\0'; -#ifdef DEBUG - fprintf(stderr, "(%s = %s)\n", key, value); -#endif dup_value = strdup(value); if (dup_value == NULL) {