[PATCH] Add close_fn in fruit and streams_xattr module

Günther Deschner gd at samba.org
Thu Dec 20 19:36:36 UTC 2018


Hi Jeremy,

On 19/12/2018 21:28, Jeremy Allison via samba-technical wrote:
> On Wed, Dec 19, 2018 at 05:46:47PM +0100, Günther Deschner via samba-technical wrote:
>> Hi,
>>
>> attached two fixes to add close_fns to fruit and streams_xattr, noticed
>> while adding fruit on top of gluster.  More patches will follow to fully
>> deal with local access to the AppleDouble files.
>>
>> Please review and push,
>> Guenther
>> -- 
>> Günther Deschner                    GPG-ID: 8EE11688
>> Red Hat                         gdeschner at redhat.com
>> Samba Team                              gd at samba.org
> 
> I don't think the first patch is *quite* right (close though).
> 
> In the open path we have:
> 
>        if (is_afpinfo_stream(smb_fname)) {
>                 fd = fruit_open_meta(handle, smb_fname, fsp, flags, mode);
>         } else if (is_afpresource_stream(smb_fname)) {
>                 fd = fruit_open_rsrc(handle, smb_fname, fsp, flags, mode);
>         } else {
>                 fd = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
>         }
> 
> fruit_open_meta() can call either fruit_open_meta_stream()
> or fruit_open_meta_netatalk() depending on config.
> 
>        switch (config->meta) {
>         case FRUIT_META_STREAM:
>                 fd = fruit_open_meta_stream(handle, smb_fname,
>                                             fsp, flags, mode);
>                 break;
> 
>         case FRUIT_META_NETATALK:
>                 fd = fruit_open_meta_netatalk(handle, smb_fname,
>                                               fsp, flags, mode);
>                 break;
> 
> The close() call below is correct for fruit_open_meta_netatalk(),
> as that opens the fruit_fake_fd() pipes, but in fruit_open_meta_stream()
> it calls:
> 
> static int fruit_open_meta_stream(vfs_handle_struct *handle,
>                                   struct smb_filename *smb_fname,
>                                   files_struct *fsp,
>                                   int flags,
>                                   mode_t mode)
> {
>         struct fruit_config_data *config = NULL;
>         struct fio *fio = NULL;
>         int open_flags = flags & ~O_CREAT;
>         int fd;
> 
>         DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname));
> 
>         SMB_VFS_HANDLE_GET_DATA(handle, config,
>                                 struct fruit_config_data, return -1);
> 
>         fio = VFS_ADD_FSP_EXTENSION(handle, fsp, struct fio, NULL);
>         fio->type = ADOUBLE_META;
>         fio->config = config;
> 
>         fd = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, open_flags, mode);
>         if (fd != -1) {
>                 return fd;
>         }
> 
> So I think below you need another function below the
> if (is_afpinfo_stream(fsp->fsp_name)) check that
> only calls close() in the config->meta==FRUIT_META_NETATALK
> case, but calls SMB_VFS_NEXT_CLOSE() in the
> config->meta==FRUIT_META_STREAM case.

Thanks for the review! You are right of course, attached is a new
version of the patch for fruit that addresses that incorrect close (the
xattr_streams patch has gone upstream already).

Next I'll be looking into the local open/read/write/etc. of the
AppleDouble files which will be a larger changeset once completed.

Please review and push,

Thanks again,
Guenther

-- 
Günther Deschner                    GPG-ID: 8EE11688
Red Hat                         gdeschner at redhat.com
Samba Team                              gd at samba.org
-------------- next part --------------
From 05aa88b81b1fc48efa6cd7d77a7ed42a1e4bc106 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCnther=20Deschner?= <gd at samba.org>
Date: Tue, 18 Dec 2018 17:18:33 +0100
Subject: [PATCH] s3-vfs-fruit: add close call
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

https://bugzilla.samba.org/show_bug.cgi?id=13725

We cannot always rely on vfs_default to close the fake fds. This mostly is
relevant when used with another non-local VFS filesystem module such as
gluster.

Guenther

Signed-off-by: Günther Deschner <gd at samba.org>
---
 source3/modules/vfs_fruit.c | 82 +++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index 19101efba74..9f3fe24e5fc 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -3719,6 +3719,87 @@ static int fruit_open(vfs_handle_struct *handle,
 	return fd;
 }
 
+static int fruit_close_meta(vfs_handle_struct *handle,
+			    files_struct *fsp)
+{
+	int ret;
+	struct fruit_config_data *config = NULL;
+
+	SMB_VFS_HANDLE_GET_DATA(handle, config,
+				struct fruit_config_data, return -1);
+
+	switch (config->meta) {
+	case FRUIT_META_STREAM:
+		ret = SMB_VFS_NEXT_CLOSE(handle, fsp);
+		break;
+
+	case FRUIT_META_NETATALK:
+		ret = close(fsp->fh->fd);
+		fsp->fh->fd = -1;
+		break;
+
+	default:
+		DBG_ERR("Unexpected meta config [%d]\n", config->meta);
+		return -1;
+	}
+
+	return ret;
+}
+
+
+static int fruit_close_rsrc(vfs_handle_struct *handle,
+			    files_struct *fsp)
+{
+	int ret;
+	struct fruit_config_data *config = NULL;
+
+	SMB_VFS_HANDLE_GET_DATA(handle, config,
+				struct fruit_config_data, return -1);
+
+	switch (config->rsrc) {
+	case FRUIT_RSRC_STREAM:
+	case FRUIT_RSRC_ADFILE:
+		ret = SMB_VFS_NEXT_CLOSE(handle, fsp);
+		break;
+
+	case FRUIT_RSRC_XATTR:
+		ret = close(fsp->fh->fd);
+		fsp->fh->fd = -1;
+		break;
+
+	default:
+		DBG_ERR("Unexpected rsrc config [%d]\n", config->rsrc);
+		return -1;
+	}
+
+	return ret;
+}
+
+static int fruit_close(vfs_handle_struct *handle,
+                       files_struct *fsp)
+{
+	int ret;
+	int fd;
+
+	fd = fsp->fh->fd;
+
+	DBG_DEBUG("Path [%s] fd [%d]\n", smb_fname_str_dbg(fsp->fsp_name), fd);
+
+	if (!is_ntfs_stream_smb_fname(fsp->fsp_name)) {
+		return SMB_VFS_NEXT_CLOSE(handle, fsp);
+	}
+
+	if (is_afpinfo_stream(fsp->fsp_name)) {
+		ret = fruit_close_meta(handle, fsp);
+	} else if (is_afpresource_stream(fsp->fsp_name)) {
+		ret = fruit_close_rsrc(handle, fsp);
+	} else {
+		ret = SMB_VFS_NEXT_CLOSE(handle, fsp);
+	}
+
+	return ret;
+}
+
 static int fruit_rename(struct vfs_handle_struct *handle,
 			const struct smb_filename *smb_fname_src,
 			const struct smb_filename *smb_fname_dst)
@@ -7029,6 +7110,7 @@ static struct vfs_fn_pointers vfs_fruit_fns = {
 	.rename_fn = fruit_rename,
 	.rmdir_fn = fruit_rmdir,
 	.open_fn = fruit_open,
+	.close_fn = fruit_close,
 	.pread_fn = fruit_pread,
 	.pwrite_fn = fruit_pwrite,
 	.pread_send_fn = fruit_pread_send,
-- 
2.19.2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20181220/f19824a1/signature.sig>


More information about the samba-technical mailing list