s3 vfs: Add a destructor to the fsp extension data API
authorTim Prouty <tprouty@samba.org>
Sun, 1 Feb 2009 04:51:04 +0000 (20:51 -0800)
committerTim Prouty <tprouty@samba.org>
Tue, 10 Feb 2009 07:46:12 +0000 (23:46 -0800)
I'm not certain if the dummy pointer is needed in struct vfs_fsp_data,
but I added it to be consistent with the comment below.

source3/include/proto.h
source3/include/smb.h
source3/include/vfs.h
source3/modules/vfs_cacheprime.c
source3/modules/vfs_commit.c
source3/modules/vfs_prealloc.c
source3/modules/vfs_streams_xattr.c
source3/smbd/vfs.c

index e5dbe60e11b3b3f59725881b8ecaabf3a1829f3e..1a1f8bef69e56cd38a1aa57bcfcf6a404d33776f 100644 (file)
@@ -7317,7 +7317,9 @@ void sys_utmp_claim(const char *username, const char *hostname,
 
 NTSTATUS smb_register_vfs(int version, const char *name, const vfs_op_tuple *vfs_op_tuples);
 bool vfs_init_custom(connection_struct *conn, const char *vfs_object);
-void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle, files_struct *fsp, size_t ext_size);
+void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle,
+                                  files_struct *fsp, size_t ext_size,
+                                  void (*destroy_fn)(void *p_data));
 void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp);
 void *vfs_memctx_fsp_extension(vfs_handle_struct *handle, files_struct *fsp);
 void *vfs_fetch_fsp_extension(vfs_handle_struct *handle, files_struct *fsp);
index 3da63cfc2b15be1cb829b738031e6317bff346ac..100ec210318b348e2da5ffcc8e16cf4e7f48b019 100644 (file)
@@ -373,7 +373,9 @@ struct rpc_cli_smbd_conn;
 struct vfs_fsp_data {
     struct vfs_fsp_data *next;
     struct vfs_handle_struct *owner;
-    /* NOTE: This structure contains two pointers so that we can guarantee
+    void (*destroy)(void *p_data);
+    void *_dummy_;
+    /* NOTE: This structure contains four pointers so that we can guarantee
      * that the end of the structure is always both 4-byte and 8-byte aligned.
      */
 };
index e9115ab8075d8f14836a4c9c3b7e9d4fd457941b..228f090600f20db641184ce198ba932e57d241f6 100644 (file)
@@ -679,8 +679,8 @@ typedef struct vfs_statvfs_struct {
 /* Add a new FSP extension of the given type. Returns a pointer to the
  * extenstion data.
  */
-#define VFS_ADD_FSP_EXTENSION(handle, fsp, type) \
-    vfs_add_fsp_extension_notype(handle, (fsp), sizeof(type))
+#define VFS_ADD_FSP_EXTENSION(handle, fsp, type, destroy_fn)           \
+    vfs_add_fsp_extension_notype(handle, (fsp), sizeof(type), (destroy_fn))
 
 /* Return a pointer to the existing FSP extension data. */
 #define VFS_FETCH_FSP_EXTENSION(handle, fsp) \
index fed051ca8d5b5040101187c076284390d7df0529..71b850505a7232033458923d5d5793a9b740ccf5 100644 (file)
@@ -54,7 +54,7 @@ static bool prime_cache(
         SMB_OFF_T * last;
         ssize_t nread;
 
-        last = (SMB_OFF_T *)VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T);
+        last = (SMB_OFF_T *)VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T, NULL);
         if (!last) {
                 return False;
         }
index 1cef6d02433b1e6d5754fed896c1057a8a7d0a67..a8105e021edb007bbda83be46ac481b2e98c558d 100644 (file)
@@ -190,7 +190,7 @@ static int commit_open(
                                         MODULE, "eof mode", "none");
 
         if (dthresh > 0 || !strequal(eof_mode, "none")) {
-                c = VFS_ADD_FSP_EXTENSION(handle, fsp, struct commit_info);
+                c = VFS_ADD_FSP_EXTENSION(handle, fsp, struct commit_info, NULL);
                 /* Process main tunables */
                 if (c) {
                         c->dthresh = dthresh;
index 5a339dbf8d4c4914271b2131227bea5adc392ad2..299f6548a15eaced7c33085e98c862e1b45b41e1 100644 (file)
@@ -164,7 +164,7 @@ static int prealloc_open(vfs_handle_struct* handle,
        if ((flags & O_CREAT) || (flags & O_TRUNC)) {
                SMB_OFF_T * psize;
 
-               psize = VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T);
+               psize = VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T, NULL);
                if (psize == NULL || *psize == -1) {
                        return fd;
                }
index 37473439dd8251e7d60173c82369fb2d1de5347e..77ffff5fb5a70642990e3538a9c5479d178301cb 100644 (file)
@@ -405,7 +405,8 @@ static int streams_xattr_open(vfs_handle_struct *handle,  const char *fname,
        }
 
         sio = (struct stream_io *)VFS_ADD_FSP_EXTENSION(handle, fsp,
-                                                       struct stream_io);
+                                                       struct stream_io,
+                                                       NULL);
         if (sio == NULL) {
                 errno = ENOMEM;
                 goto fail;
index df5a39eea2e064c2d2ce2f546f077930014df784..515e557f67e02f170dc0f70f558d8a298296702b 100644 (file)
@@ -220,7 +220,9 @@ bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
 
 #define EXT_DATA_AREA(e) ((uint8 *)(e) + sizeof(struct vfs_fsp_data))
 
-void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle, files_struct *fsp, size_t ext_size)
+void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle,
+                                  files_struct *fsp, size_t ext_size,
+                                  void (*destroy_fn)(void *p_data))
 {
        struct vfs_fsp_data *ext;
        void * ext_data;
@@ -238,6 +240,7 @@ void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle, files_struct *fsp,
 
        ext->owner = handle;
        ext->next = fsp->vfs_extension;
+       ext->destroy = destroy_fn;
        fsp->vfs_extension = ext;
        return EXT_DATA_AREA(ext);
 }
@@ -256,6 +259,9 @@ void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
                    } else {
                            fsp->vfs_extension = curr->next;
                    }
+                   if (curr->destroy) {
+                           curr->destroy(EXT_DATA_AREA(curr));
+                   }
                    TALLOC_FREE(curr);
                    return;
                }