Rework of VFS is_offline() function to only return boolean offline/online result...
authorAlexander Bokovoy <ab@samba.org>
Thu, 17 Jan 2008 11:57:35 +0000 (14:57 +0300)
committerAlexander Bokovoy <ab@samba.org>
Thu, 17 Jan 2008 11:57:35 +0000 (14:57 +0300)
This makes sense as upper levels are only taking returned result of 0
(no error) into consideration when deciding whether to mark file
offline/online as returned from is_offline.

That means that we simply can move the decision down to VFS module and
clean up upper levels so that they always see only file status. If there
is an error when trying to identify file status, then VFS module could
decide what to return (offline or online) by itself -- after all, it
ought to have system-specific knowledge anyway.
(This used to be commit 75cc08661473cce62756fa062071bb2bc1fb39ec)

examples/VFS/skel_opaque.c
examples/VFS/skel_transparent.c
source3/include/vfs.h
source3/include/vfs_macros.h
source3/modules/vfs_default.c
source3/modules/vfs_tsmsm.c
source3/smbd/dosmode.c

index 1c2fc4501183672a18acf9a4c2b677a546f3cade..42154c47a66682c283e499e6b7d6755a65d25d3e 100644 (file)
@@ -585,9 +585,9 @@ static bool skel_aio_force(struct vfs_handle_struct *handle, struct files_struct
        return vfswrap_aio_force(NULL, fsp);
 }
 
-static int skel_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf, bool *offline)
+static bool skel_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf)
 {
-       return vfswrap_set_offline(NULL, path, sbuf, offline);
+       return vfswrap_is_offline(NULL, path, sbuf);
 }
 
 static int skel_set_offline(struct vfs_handle_struct *handle, const char *path)
index 0a934976c45db85aa74567aff404a3d7e73b1390..997783819c03c689db78af922e2136a3eab07a42 100644 (file)
@@ -544,9 +544,9 @@ static bool skel_aio_force(struct vfs_handle_struct *handle, struct files_struct
         return SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
 }
 
-static int skel_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf, bool *offline)
+static bool skel_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf)
 {
-       return SMB_VFS_NEXT_IS_OFFLINE(handle, path, sbuf, offline);
+       return SMB_VFS_NEXT_IS_OFFLINE(handle, path, sbuf);
 }
 
 static int skel_set_offline(struct vfs_handle_struct *handle, const char *path)
index b0da7e81a5fdf19814b0c28bfdb0eda19ced55f0..da5494927e1e2f718b11f994f3bfc0b8937fbbbc 100644 (file)
@@ -413,7 +413,7 @@ struct vfs_ops {
                bool (*aio_force)(struct vfs_handle_struct *handle, struct files_struct *fsp);
 
                /* offline operations */
-               int (*is_offline)(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf, bool *offline);
+               bool (*is_offline)(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf);
                int (*set_offline)(struct vfs_handle_struct *handle, const char *path);
                bool (*is_remotestorage)(struct vfs_handle_struct *handle, const char *path);
 
index 39f245fa35bcdc80c36bcd9e57dfa55e80026387..f7c7e7d623a17352b5f83fd5b5d5d1fc33b37521 100644 (file)
 #define SMB_VFS_AIO_FORCE(fsp) ((fsp)->conn->vfs.ops.aio_force((fsp)->conn->vfs.handles.aio_force,(fsp)))
 
 /* Offline operations */
-#define SMB_VFS_IS_OFFLINE(conn,path,sbuf,offline) ((conn)->vfs.ops.is_offline((conn)->vfs.handles.is_offline,(path),(sbuf),(offline)))
+#define SMB_VFS_IS_OFFLINE(conn,path,sbuf) ((conn)->vfs.ops.is_offline((conn)->vfs.handles.is_offline,(path),(sbuf)))
 #define SMB_VFS_SET_OFFLINE(conn,path) ((conn)->vfs.ops.set_offline((conn)->vfs.handles.set_offline,(path)))
 #define SMB_VFS_IS_REMOTESTORAGE(conn,path) ((conn)->vfs.ops.is_remotestorage((conn)->vfs.handles.is_remotestorage,(path)))
 
 #define SMB_VFS_OPAQUE_AIO_FORCE(fsp) ((fsp)->conn->vfs_opaque.ops.aio_force((fsp)->conn->vfs_opaque.handles.aio_force,(fsp)))
 
 /* Offline operations */
-#define SMB_VFS_OPAQUE_IS_OFFLINE(conn,path,sbuf,offline) ((conn)->vfs_opaque.ops.is_offline((conn)->vfs_opaque.handles.is_offline,(path),(sbuf),(offline)))
+#define SMB_VFS_OPAQUE_IS_OFFLINE(conn,path,sbuf) ((conn)->vfs_opaque.ops.is_offline((conn)->vfs_opaque.handles.is_offline,(path),(sbuf)))
 #define SMB_VFS_OPAQUE_SET_OFFLINE(conn,path) ((conn)->vfs_opaque.ops.set_offline((conn)->vfs_opaque.handles.set_offline,(path)))
 #define SMB_VFS_OPAQUE_IS_REMOTESTORAGE(conn,path) ((conn)->vfs_opaque.ops.is_remotestorage((conn)->vfs_opaque.handles.is_remotestorage,(path)))
 
 #define SMB_VFS_NEXT_AIO_FORCE(handle,fsp) ((handle)->vfs_next.ops.aio_force((handle)->vfs_next.handles.aio_force,(fsp)))
 
 /* Offline operations */
-#define SMB_VFS_NEXT_IS_OFFLINE(handle,path,sbuf,offline) ((handle)->vfs_next.ops.is_offline((handle)->vfs_next.handles.is_offline,(path),(sbuf),(offline)))
+#define SMB_VFS_NEXT_IS_OFFLINE(handle,path,sbuf) ((handle)->vfs_next.ops.is_offline((handle)->vfs_next.handles.is_offline,(path),(sbuf)))
 #define SMB_VFS_NEXT_SET_OFFLINE(handle,path) ((handle)->vfs_next.ops.set_offline((handle)->vfs_next.handles.set_offline,(path)))
 #define SMB_VFS_NEXT_IS_REMOTESTORAGE(handle,path) ((handle)->vfs_next.ops.is_remotestorage((handle)->vfs_next.handles.is_remotestorage,(path)))
 
index d4ba4dc6117483d151a1db10b9bc13e50f7da89e..755bcdeefa25f818811b2fb45061819d7a9fd7c8 100644 (file)
@@ -1230,22 +1230,20 @@ static bool vfswrap_aio_force(struct vfs_handle_struct *handle, struct files_str
        return false;
 }
 
-static int vfswrap_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf, bool *offline)
+static bool vfswrap_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf)
 {
        if (ISDOT(path) || ISDOTDOT(path)) {
-               *offline = false;
-               return 0;
+               return false;
        }
 
        if (!lp_dmapi_support(SNUM(handle->conn)) || !dmapi_have_session()) {
 #if defined(ENOTSUP)
                errno = ENOTSUP;
 #endif
-               return -1;
+               return false;
        }
 
-       *offline = (dmapi_file_flags(path) & FILE_ATTRIBUTE_OFFLINE) != 0;
-       return 0;
+       return (dmapi_file_flags(path) & FILE_ATTRIBUTE_OFFLINE) != 0;
 }
 
 static int vfswrap_set_offline(struct vfs_handle_struct *handle, const char *path)
index c2d826f818b563002c7f8a844756b1fea172441b..c737032907a3fdbc96e6a689b7d3f315537a1544 100644 (file)
@@ -136,24 +136,23 @@ static int tsmsm_connect(struct vfs_handle_struct *handle,
         return SMB_VFS_NEXT_CONNECT(handle, service, user); 
 }
 
-static int tsmsm_is_offline(struct vfs_handle_struct *handle, 
+static bool tsmsm_is_offline(struct vfs_handle_struct *handle, 
                            const char *path,
-                           SMB_STRUCT_STAT *stbuf,
-                           bool *offline) {
+                           SMB_STRUCT_STAT *stbuf) {
        struct tsmsm_struct *tsmd = (struct tsmsm_struct *) handle->data;
        void *dmhandle = NULL;
        size_t dmhandle_len = 0;
        size_t rlen;
        dm_attrname_t dmname;
        int ret;
+       bool offline;
 
         /* if the file has more than FILE_IS_ONLINE_RATIO of blocks available,
           then assume it is not offline (it may not be 100%, as it could be sparse) */
        if (512 * (off_t)stbuf->st_blocks >= stbuf->st_size * tsmd->online_ratio) {
-               *offline = false;
                DEBUG(10,("%s not offline: st_blocks=%ld st_size=%ld online_ratio=%.2f\n", 
                          path, stbuf->st_blocks, stbuf->st_size, tsmd->online_ratio));
-               return 0;
+               return false;
        }
        
         /* using POSIX capabilities does not work here. It's a slow path, so 
@@ -167,10 +166,9 @@ static int tsmsm_is_offline(struct vfs_handle_struct *handle,
 
        /* go the slow DMAPI route */
        if (dm_path_to_handle((char*)path, &dmhandle, &dmhandle_len) != 0) {
-               ret = -1;
                DEBUG(2,("dm_path_to_handle failed - assuming offline (%s) - %s\n", 
                         path, strerror(errno)));
-               *offline = true;
+               offline = true;
                goto done;
        }
 
@@ -181,7 +179,7 @@ static int tsmsm_is_offline(struct vfs_handle_struct *handle,
                            DM_NO_TOKEN, &dmname, 0, NULL, &rlen);
 
        /* its offline if the IBMObj attribute exists */
-       *offline = (ret == 0 || (ret == -1 && errno == E2BIG));
+       offline = (ret == 0 || (ret == -1 && errno == E2BIG));
 
        DEBUG(10,("dm_get_dmattr %s ret=%d (%s)\n", path, ret, strerror(errno)));
 
@@ -191,7 +189,7 @@ static int tsmsm_is_offline(struct vfs_handle_struct *handle,
 
 done:
        unbecome_root();
-       return ret;
+       return offline;
 }
 
 
index 2021621dfa0c94e54b74410af85c8d61184c08e1..eb18f65fca9dc4541925294778c758d9e361ad24 100644 (file)
@@ -350,7 +350,6 @@ uint32 dos_mode(connection_struct *conn, const char *path,SMB_STRUCT_STAT *sbuf)
 {
        uint32 result = 0;
        bool offline;
-       int ret;
 
        DEBUG(8,("dos_mode: %s\n", path));
 
@@ -381,8 +380,8 @@ uint32 dos_mode(connection_struct *conn, const char *path,SMB_STRUCT_STAT *sbuf)
        }
 
        
-       ret = SMB_VFS_IS_OFFLINE(conn, path, sbuf, &offline);
-       if (S_ISREG(sbuf->st_mode) && (ret == 0) && offline) {
+       offline = SMB_VFS_IS_OFFLINE(conn, path, sbuf);
+       if (S_ISREG(sbuf->st_mode) && offline) {
                result |= FILE_ATTRIBUTE_OFFLINE;
        }