Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iscsi+smbfs #621

Closed
wants to merge 12 commits into from
Closed

Iscsi+smbfs #621

wants to merge 12 commits into from

Conversation

FransUrbo
Copy link
Contributor

Both iSCSI and SMB support into one pull request. Solves #492 and #493.

Current problems:

  • 'unshare -a' seems to sometimes not work. Currently working on finding out why...
    zfs: ../../cmd/zfs/zfs_main.c:5915: Assertion `zfs_prop_get(zhp, ZFS_PROP_SHAREISCSI, nfsiscsi_mnt_prop, sizeof (nfsiscsi_mnt_prop), NULL, NULL, 0, B_FALSE) == 0' failed.
  • Does not share when setting 'shareiscsi=on'. Works with 'sharesmb=on' though. Working on this to.
  • Only works with iSCSITarget (using 'ietadm'). Will not support other personaly.

@FransUrbo
Copy link
Contributor Author

Ok, managed to figure out why I got the Assertion. Fixed locally. Trying to find a solution to point two before I push to github.

@behlendorf
Copy link
Contributor

Please take a look at the inline comments. I'm happy to make a another pass when you pushed a reworked version. I'd also really like to see the DEBUG code dropped because at this point we shouldn't need it and it really hurts readability.

Thanks for working on this!

@FransUrbo
Copy link
Contributor Author

Fixed all this in a new push (commit 54711e52810f55f5b8152b3a3cc253c5d5386601). EXEPT the TODO function!

Should I rebase my changes and then update my pull request?

@behlendorf
Copy link
Contributor

Yes, please. Go ahead and rebase your changes squashing the fixes in and force repush the branch.

@FransUrbo
Copy link
Contributor Author

Ok, rebased after five or six tries! That command is HARD!! :). Many of your previous comments on the SMB patch could probably be applied to the iSCSI patch as well, but I'll wait for your comments to be sure :).


/* ====== */
/* Part 3 */
argv[0] = (char*)"/sbin/zfs_share_iscsi.sh";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command is never actually called.

@prakashsurya
Copy link
Member

@FransUrbo I have a renewed interest in landing SMB support for this project soon and would like to help push it forward. Would you mind if I look through the patch and clean up some of it's rough edges?

@FransUrbo
Copy link
Contributor Author

Most of what's mentioned here, have already been fixed. It might not show, because I have to do a force push to Github which overwrites the code discussed.

And Brian and Richard is already reviewing the code, and I'm fixing it as soon as they have given me opinions.
But if you want to help, you can help by testing it, maybe have a look at the test shell script and come up with and write more test cases to really make sure that everything works as it's supposed.

OR, figure out why it doesn't share automatically when you 'set shareiscsi=on' like the smb/nfs do.

@prakashsurya
Copy link
Member

Can you remove commit, 32312b9, from the pull request. It looks like that is not intended to land in the first place, so it only adds confusion when reviewing the patches. Send me a email/message if you are unfamiliar with git and are unsure how to do this, I'll try to help you out.

@FransUrbo
Copy link
Contributor Author

Ok, a new rebase and a forced push have been done, fixing issues mentioned.

@behlendorf
Copy link
Contributor

Thanks for the refreshed patch. I'm going to actually try and use it this weekend and see what sorts of issues I run in too.

@ryao
Copy link
Contributor

ryao commented Apr 1, 2012

  • Compile zvol_id without CFLAGS to avoid strange behaviour.
    Quick, dirty fix.

@FransUrbo What sort of behavior did you observe? Does it only occur in the presence of these patches? If not, is there an open bug on it?

@FransUrbo
Copy link
Contributor Author

I can't remember if we ever figured out exactly why/when it happens. But it might have something to do with 32/64 bit 'conversion something' :). It do happen without these patches and the behaviour is that zvol_id can't figure out the device path. It only gives garbage or nothing at all.

Check the list, two/three months ago.

@behlendorf
Copy link
Contributor

The zvol issue is probably unrelated. There were some reports of stack smashing occurring in issue #569. I made a start to cleanup this little helper utility but didn't quite get it done and tested. WIP here:

https://github.com/behlendorf/zfs/tree/issue-569

@ryao
Copy link
Contributor

ryao commented Apr 2, 2012

@FransUrbo, In that case, it might not be appropriate to address that issue as part of this commit.

Note that I have a downstream motivation for saying this. Gentoo's ZFS ebuilds filter CFLAGS against a white-list that is global to the distribution. Users that know enough to provide useful bug reports are free to disable it. If the CFLAGS change is committed, I will be expected to revert it downstream.

@ryao
Copy link
Contributor

ryao commented Apr 3, 2012

@FransUrbo I am encountering the following error:

vserver ~ # zfs share rpool/KVM/zfs-test
ERROR: Can't get domainname: No such file or directory
cannot share 'rpool/KVM/zfs-test': iSCSI add share failed

Looking at the code, getdomainname is returning ENOENT. getdomainname is a GNU-extension implemented by glibc [1]. Not all Linux distributions use glibc as their system library and while uclibc also implements this, that cannot be guarenteed for other libc implementations [2]. It might not be a good idea to rely on such extensions. As far as I can tell, what it actually provides is poorly defined [3], which is probably why it is broken on my system.

Perhaps we could use gethostname here instead. That should be the equivalent of uname -n, which is well defined.

1: http://linux.die.net/man/2/getdomainname
2: http://cristi.indefero.net/p/uClibc-cristi/source/tree/840d49dc036274b0fded03b30c8d4a92c432378e/libc/sysdeps/linux/common/getdomainname.c
3: http://linux.die.net/man/2/uname

/* PART 1 */
snprintf(params_name, sizeof (params_name), "Name=%s", sharename);

/* int: between -2,147,483,648 and 2,147,483,647 => 10 chars + NUL */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is tid_s 16 characters in size then?

@@ -908,8 +908,6 @@ rpm-modules: srpm-modules
rpm-utils: srpm-utils
$(MAKE) $(AM_MAKEFLAGS) pkg="${PACKAGE}" rpm-common

rpm-modules: srpm-modules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change for? Can it be part of a separate pull request?

@ryao
Copy link
Contributor

ryao commented Apr 4, 2012

@FransUrbo The issue with strlen inside of loops is that it is (usually) loop invariant, but the compiler is not capable of the analysis necessary to determine that, so it will be executed each iteration, wasting CPU resources. In cases when it is not loop variant, you can usually use a counter to keep track of what its output would be.

I suggest that you rework code using it to only call it once at the beginning of a loop. Store the result in a separate variable and work with that instead.

@prakashsurya
Copy link
Member

@FransUrbo Isn't a strncpy(dst, src, strlen(src)) just as "bad" as strcpy(dst, src)? Neither method takes into account the size of dst, thus buffer overflows are rampant in both. Ideally, you'd want to use something along the lines of strncpy(dst, src, sizeof(dst)).

@rlaager
Copy link
Member

rlaager commented Apr 4, 2012

Actually, that's not safe either. Assuming you just want truncation, do this:
strncpy(dst, src, sizeof(dst)-1); dst[sizeof(dst)-1] = '\0';

See: https://www.securecoding.cert.org/confluence/display/seccode/STR32-C.+Null-terminate+byte+strings+as+required

@prakashsurya
Copy link
Member

Yes, indeed my example was not entirely complete. You need the assignment of '\0' to ensure dst is null terminated.

@FransUrbo
Copy link
Contributor Author

But size of on a 'char*'... ?

@ryao
Copy link
Contributor

ryao commented Apr 5, 2012

@FransUrbo After you rework the code copying strings, it might be worthwhile to open a new pull request. There is a great deal of clutter in this one and it becoming difficult to follow.

@FransUrbo
Copy link
Contributor Author

Where is the clutter, and what´s wrong with 'Misc personal changes'? Is there a way to remove only that part from the pull request, but not for my commits?

@FransUrbo
Copy link
Contributor Author

New push after fixing:
* Spelling errors fixed.
* ietadm is in man section '8', not '8M' (to much cut-and-past :).
* Remove (rewrite) some redundant strlen() usage.

@pyavdr
Copy link
Contributor

pyavdr commented Apr 10, 2012

@FransUrbo

Thank you for your commits. When Brian merges it, i would like to try.

Did you observe, that the names of the zvol devices ( /dev/zd*) changes after reboot, when
there are several zvols and zvols are removed or added ? Even on snapshot of a zvol
there are additional zvol names appearing.
Maybe it is only my system (opensuse) which behaves like that.
Did you see/check that ?

@FransUrbo
Copy link
Contributor Author

If this is true, it is not because of my patch and I have not noticed this. But even if this is so (that they change name), it does not matter. Not from the SMB/iSCSI patch point of view. If you find this a problem anyway, please file a bug report about this or take it up on the mailinglist.

And you can still test this/these patch(es) by checking out my branch.

@pyavdr
Copy link
Contributor

pyavdr commented Apr 10, 2012

Ok,
there are several issuses already filed. Maybe i hit #599, on VMWare the /dev/by-id is not populated and some of the zvol functionality maybe strange.

Sixth official patch attempt. Previous ones was/is lost
in my inability with GIT.
* Fix issues after review by behlendorf.
  = Move comments etc from the README to the code and to the manpage.
  = Adhere to the 80 char line limit.
  = Cast constants when setting argv[x].
  = More defines, concentrated at the top.
  = Move smb_retrieve_shares() to the top, to avoid forward declaration.
  = Make private functions static.
  = Remove all debugging.
  = Whitespace fixes.
  = Return SA_OK instead of 0 where needed.
  = Remove some fprintf(stderr, "ERROR: ...") strings. Not needed really,
    they where mostly for debugging any way.
  = Bump release.
  = Add missing locale.h include.
  = Add file_is_executable().
  = Remove file_is_executable() per request from Brian.

* Some minor SMBFS fixes, comments from Richard Laager:
  = Remove redundant variable = NULL check.
  = Rewrite static 'net' command options define's
  = Remove commented out/redundant line parsing code.
  = Add Samba host options to net command in smb_disable_share_one()
    as well.

* Fixes after second review by behlendorf.
  = Putting back things that wasn't mine that I removed or
    changed..
  = Remove the file_is_executable() declaration that came
    back some how.
  = Reword, rewrite and indent information about how to
    setup Samba.
  = Implement smb_validate_shareopts().

* Fixes after third review by Prakash-Surya.
  = Removed missplaced space.
Sixth official patch attempt. Previous ones was/is lost
in my inability with GIT.
* Script to run through some tests to test share/unsharing...
* Debugging output added.
* Retabbing
* Fix faulty nfs|smb check (setting ZFS_TYPE_FILESYSTEM). Now possible to
  use 'share -a [nfs|smb|iscsi] as command line suggests. Not documented
  in man page though...
  + In unshare_unmount(), 'if(do_all)', 'continue' instead of 'break' after
    checking 'sharenfs=off' (so that we can continue checking for shareiscsi
    and sharesmb).
* Process iscsi shares early in update_zfs_shares_cb().
* Fix problem with assertion fail when running 'zfs unshare -a'.
* Call process_share() early of update_zfs_shares_cb() if iSCSI.
* Add shell script (test_zfs.sh) to test some functionality of SMB/iSCSI
  patch(es).
+ Remove file_is_executable() from iSCSI per request from Brian.

Fix some stuff that I know Brian will nag about :)
* 80 char line
* Move content of README to code + man page.
* Remove all debugging.
* Return SA_OK instead of 0 where needed.
* Cast to char* when setting argv with constant string(s).
* C9x compliance
* Make private functions static.

Some minor iSCSI fixes, comments from Richard Laager:
* Remove redundant variable = NULL check.
* Rename the custom iSCSI share script (remove .sh suffix).
  + Reword manual

Some more iSCSI fixes.
* Since iscsi_retrieve_targets() is now static, move it
  up to the top of iscsi.c and remove from iscsi.h.
* In update_zfs_shares_cb(), do the iSCSI parts later
  and skip the if type != FS check etc.
* Implement iscsi_validate_shareopts().
* Distinguish between FS and VOL when updating
  share information.
  + Support adding a VOL to list.
* Uncomment some stuff in process_share() that is/was supposed
  to possibly fix the 'shareicsi=on' auto sharing but didn't.
  Only made it to not compile...
* Update copyright note and year(s).

Fixes after second review by behlendorf and comments by Richard Yao.
* Check for getdomainname() - set HAVE_GETDOMAINNAME=1 if so - in
  ./configure.
  + Only try to get domain name with getdomainname() if
    we have it (HAVE_GETDOMAINNAME). If we don't, use the
    file /etc/domainname (configurable with DOMAINNAME_FILE).
* s/if\(/if \(/.
* Init iscsi_volumes_fp in iscsi_retrieve_targets() to NULL.
* Make sure tid_s is only 11 chars long.
* Remove one level of indentation from test binary.
* Don't malloc temp - memleak in test binary.
* Retabbing.
* s/share/tank/g in comments etc.

More fixes after review by Richard Yao, Richard Laager and Prakash Surya:
* Spelling errors fixed.
* ietadm is in man section '8', not '8M' (to much cut-and-past :).
* Remove (rewrite) some redundant strlen() usage.
* Replace a non-working sizeof with strlen.

Other changes and fixes:
* Update Release to indicate date and branch.
* Remove trailing newline/null in domainname (was cutting a char to
  much).
* Put the extra share script (/sbin/zfs_share_iscsi) as a define.
* Optional /etc/iscsi_target_id which contain the TID - this instead
  of autogenerating one (which changes every month!).
* Rewrite domain name information for iSCSI.
* Document new optional /etc/iscsi_target_id and it's use.
* Update list [iscsi] targets using iscsitadm with something that
  works in Linux.
@behlendorf
Copy link
Contributor

@FransUrbo First off thanks for keeping these patches refreshed. I know they've been pending for a long time, but I think we can partially move on this.

The samba patches are largely self contained and quite safe. So I'm willing to pull those changes in to master for the next release if your willing to maintain that code. I just don't have the time to spend any cycles on fixing samba integration issues.

The iscsi changes are more disruptive and frankly the right solution here is a lot less clear. But at least this gets you down to a single patch.

@FransUrbo
Copy link
Contributor Author

On Nov 15, 2012, at 10:11 PM, Brian Behlendorf wrote:

So I'm willing to pull those changes in to master for the next release if your willing to maintain that code.

Sure, no problem. I haven't touch the code in months and haven't heard
any issues with it so I consider it done.

@behlendorf
Copy link
Contributor

@FransUrbo Sounds good. Just two requests before I pull in the samba changes.

  • Open a clean pull request against master with just just the latest samba patch.
  • Drop the Solaris specific bits from the sharesmb=on section of zfs.8 man page and replace it with as much Linux specific detail as end users will need to get going.

@FransUrbo
Copy link
Contributor Author

I might have jumped the gun a little there. When running through my checks again, I noticed that although a unshare worked, the zfs command claimed that it was unsuccessful because it couldn't find the 'unshare' command. Fixed that, but it required some changes to lib/libzfs/libzfs_mount.c that you might not like (disruptive, same as the iscsi patch - not as big, but still). I'll do a new push shortly for you to review.

In the meantime, how about this wording for the man page:

   sharesmb=on | off
       Controls whether the file system is shared by using Samba, and what options are to be used.
       Otherwise, the file  system  is  automatically shared and unshared with the zfs share and zfs
       unshare commands. If the property is set to on, the net(8) command is invoked to create a USERSHARE.

       Because SMB shares requires a resource name, a unique resource name is constructed from
       the dataset  name.  The  constructed name is a copy of the dataset name except that the
       characters in the dataset name, which would be illegal in the resource name, are replaced with
       underscore (_) characters. The ZFS On Linux driver does not (yet) support  additional options
       which might be availible in the Solaris version.

       If the sharesmb property is set to off, the file systems are unshared.

       In  Linux,  the  share  is created with the acl "Everyone:F" by default, meaning that everyone
       have read access. This however isn’t the full truth: Any access control on the underlaying
       filesystem supersedes this.

Also, I don't currently support any optional parameters to sharesmb (because I can't figure out how sharenfs does it! :). If anyone have any interest in lending a help, I'll be grateful.

@behlendorf
Copy link
Contributor

@FransUrbo I'll review the new changes you needed to make and we should be able to get them in a form which is acceptable. Plus if we accidentally break something now I know who to assign the open issues too! At least this will help lay the ground work and make it easier for other to contribute.

The updated man page looks pretty good. The real test will be if I can successfully setup a ZoL system to use Samba using those directions.

@FransUrbo
Copy link
Contributor Author

Ok, I've tried three times now, but I still get 11 commits! I have done a rebase against master and in the git logs all looks ok... Any ideas?

@FransUrbo
Copy link
Contributor Author

By the way, could you close the 'Iscsi+smbfs' pull req? I'll do a new one with only the iscsi part so we have two separate ones...

@behlendorf
Copy link
Contributor

Closed

@behlendorf behlendorf closed this Nov 16, 2012
@behlendorf behlendorf modified the milestone: 0.6.7 Nov 8, 2014
pcd1193182 added a commit to pcd1193182/zfs that referenced this pull request Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Feature request or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants