smbd: refactor disk_free handling
authorUri Simchoni <uri@samba.org>
Sun, 10 Jan 2016 13:15:41 +0000 (15:15 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 26 Jan 2016 14:58:12 +0000 (15:58 +0100)
Move most of the logic that handles determination of
disk size and free space from default VFS handler to
the SMB layer - letting the VFS handle the basic task
of querying the file system for general stats and
quota.

Signed-off-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/modules/vfs_default.c
source3/smbd/dfree.c
source3/smbd/proto.h
source3/smbd/quotas.c

index 0f8e067363ff45dd6b185653fea6f0b0eb23feae..2eb9a1794a08688243c768d8e3302c6188557ef0 100644 (file)
@@ -58,10 +58,12 @@ static uint64_t vfswrap_disk_free(vfs_handle_struct *handle, const char *path,
                                  uint64_t *bsize, uint64_t *dfree,
                                  uint64_t *dsize)
 {
-       uint64_t result;
+       if (sys_fsusage(path, dfree, dsize) != 0) {
+               return (uint64_t)-1;
+       }
 
-       result = sys_disk_free(handle->conn, path, bsize, dfree, dsize);
-       return result;
+       *bsize = 512;
+       return *dfree / 2;
 }
 
 static int vfswrap_get_quota(struct vfs_handle_struct *handle, const char *path,
index 32a3a69ac4d62fbb91065e9987fbe4cb43318f66..6b7993c16b8305330519969e4e3eee0fc0b067cb 100644 (file)
@@ -116,13 +116,14 @@ uint64_t sys_disk_free(connection_struct *conn, const char *path,
                           syscmd, strerror(errno) ));
        }
 
-       if (sys_fsusage(path, dfree, dsize) != 0) {
-               DEBUG (0, ("disk_free: sys_fsusage() failed. Error was : %s\n",
-                       strerror(errno) ));
+       if (SMB_VFS_DISK_FREE(conn, path, bsize, dfree, dsize) ==
+           (uint64_t)-1) {
+               DBG_ERR("VFS disk_free failed. Error was : %s\n",
+                       strerror(errno));
                return (uint64_t)-1;
        }
 
-       if (disk_quotas(path, &bsize_q, &dfree_q, &dsize_q)) {
+       if (disk_quotas(conn, path, &bsize_q, &dfree_q, &dsize_q)) {
                (*bsize) = bsize_q;
                (*dfree) = MIN(*dfree,dfree_q);
                (*dsize) = MIN(*dsize,dsize_q);
@@ -170,7 +171,7 @@ uint64_t get_dfree_info(connection_struct *conn,
        uint64_t dfree_ret;
 
        if (!dfree_cache_time) {
-               return SMB_VFS_DISK_FREE(conn, path, bsize, dfree, dsize);
+               return sys_disk_free(conn, path, bsize, dfree, dsize);
        }
 
        if (dfc && (conn->lastused - dfc->last_dfree_time < dfree_cache_time)) {
@@ -181,7 +182,7 @@ uint64_t get_dfree_info(connection_struct *conn,
                return dfc->dfree_ret;
        }
 
-       dfree_ret = SMB_VFS_DISK_FREE(conn, path, bsize, dfree, dsize);
+       dfree_ret = sys_disk_free(conn, path, bsize, dfree, dsize);
 
        if (dfree_ret == (uint64_t)-1) {
                /* Don't cache bad data. */
index 847a19174b1a66749902fb5966215ffc9048c69c..3479b3b5096f90e9d1ce24b3d612099c9f88f0ff 100644 (file)
@@ -830,7 +830,8 @@ bool fork_echo_handler(struct smbXsrv_connection *xconn);
 
 /* The following definitions come from smbd/quotas.c  */
 
-bool disk_quotas(const char *path, uint64_t *bsize, uint64_t *dfree, uint64_t *dsize);
+bool disk_quotas(connection_struct *conn, const char *path, uint64_t *bsize,
+                uint64_t *dfree, uint64_t *dsize);
 bool disk_quotas_vxfs(const char *name, char *path, uint64_t *bsize, uint64_t *dfree, uint64_t *dsize);
 
 /* The following definitions come from smbd/reply.c  */
index 3b23e6b2abebd50ba0695cd082b10928324eb74c..cbdec6b4996e97fd941bad08cbd57c2c333bcbe4 100644 (file)
@@ -236,10 +236,8 @@ try to get the disk space from disk quotas (SunOS & Solaris2 version)
 Quota code by Peter Urbanec (amiga@cse.unsw.edu.au).
 ****************************************************************************/
 
-bool disk_quotas(const char *path,
-               uint64_t *bsize,
-               uint64_t *dfree,
-               uint64_t *dsize)
+bool disk_quotas(connection_struct *conn, const char *path, uint64_t *bsize,
+                uint64_t *dfree, uint64_t *dsize)
 {
        uid_t euser_id;
        int ret;
@@ -428,7 +426,8 @@ bool disk_quotas(const char *path,
 try to get the disk space from disk quotas - default version
 ****************************************************************************/
 
-bool disk_quotas(const char *path, uint64_t *bsize, uint64_t *dfree, uint64_t *dsize)
+bool disk_quotas(connection_struct *conn, const char *path, uint64_t *bsize,
+                uint64_t *dfree, uint64_t *dsize)
 {
   int r;
   struct dqblk D;
@@ -658,7 +657,8 @@ bool disk_quotas_vxfs(const char *name, char *path, uint64_t *bsize, uint64_t *d
 
 #else /* WITH_QUOTAS */
 
-bool disk_quotas(const char *path,uint64_t *bsize,uint64_t *dfree,uint64_t *dsize)
+bool disk_quotas(connection_struct *conn, const char *path, uint64_t *bsize,
+                uint64_t *dfree, uint64_t *dsize)
 {
        (*bsize) = 512; /* This value should be ignored */
 
@@ -676,7 +676,8 @@ bool disk_quotas(const char *path,uint64_t *bsize,uint64_t *dfree,uint64_t *dsiz
 /* wrapper to the new sys_quota interface
    this file should be removed later
    */
-bool disk_quotas(const char *path,uint64_t *bsize,uint64_t *dfree,uint64_t *dsize)
+bool disk_quotas(connection_struct *conn, const char *path, uint64_t *bsize,
+                uint64_t *dfree, uint64_t *dsize)
 {
        int r;
        SMB_DISK_QUOTA D;
@@ -685,7 +686,7 @@ bool disk_quotas(const char *path,uint64_t *bsize,uint64_t *dfree,uint64_t *dsiz
        id.uid = geteuid();
 
        ZERO_STRUCT(D);
-       r=sys_get_quota(path, SMB_USER_QUOTA_TYPE, id, &D);
+       r = SMB_VFS_GET_QUOTA(conn, path, SMB_USER_QUOTA_TYPE, id, &D);
 
        /* Use softlimit to determine disk space, except when it has been exceeded */
        *bsize = D.bsize;
@@ -723,7 +724,7 @@ try_group_quota:
        id.gid = getegid();
 
        ZERO_STRUCT(D);
-       r=sys_get_quota(path, SMB_GROUP_QUOTA_TYPE, id, &D);
+       r = SMB_VFS_GET_QUOTA(conn, path, SMB_GROUP_QUOTA_TYPE, id, &D);
 
        /* Use softlimit to determine disk space, except when it has been exceeded */
        *bsize = D.bsize;