]> arthur.barton.de Git - netatalk.git/commitdiff
Use uint64_t instead of off_t for VolSpace
authorFrank Lahm <franklahm@googlemail.com>
Mon, 28 Nov 2011 10:48:22 +0000 (11:48 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Mon, 28 Nov 2011 10:48:22 +0000 (11:48 +0100)
The quota code doesn't work with off_t. Update NEWS.

NEWS
etc/afpd/unix.c
etc/afpd/volume.c
include/atalk/volume.h
man/man5/AppleVolumes.default.5.tmpl

diff --git a/NEWS b/NEWS
index 626aa3e8be1543d443427ec93b60361a73b9a0cd..ec6cd6240f69262a2def3895d7e78c682fdbeaef 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,9 @@ Changes in 2.2.2
 * UPD: afpd: Convert passwords from legacy encoding (wire format) to host
        encoding
 * UPD: afpd: Don't set ATTRBIT_SHARED flag for directories
+* UPD: afpd: Use sendfile() on Solaris and FreeBSD for sending data
+* UPD: afpd: Faster volume used size calculation for "volsizelimit" option,
+       cf man AppleVolume.default for details
 * FIX: afpd: ACL access checking
 * FIX: afpd: Fix an error when duplicating files that lacked an AppleDouble
        file which lead to a possible Finder crash
index 9eafa7e0f6bb1150196cba3b3ea6a69778f1a85d..8d60a6ef61cca4a547e0ffe6bdfc1e9e6f534c7b 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <inttypes.h>
 
 /* STDC check */
 #ifdef STDC_HEADERS
@@ -52,7 +53,7 @@ char *strchr (), *strrchr ();
  */
 int ustatfs_getvolspace(const struct vol *vol, VolSpace *bfree, VolSpace *btotal, u_int32_t *bsize)
 {
-    VolSpace maxVolSpace = INTMAX_MAX;
+    VolSpace maxVolSpace = UINT64_MAX;
 
 #ifdef ultrix
     struct fs_data     sfs;
@@ -60,7 +61,6 @@ int ustatfs_getvolspace(const struct vol *vol, VolSpace *bfree, VolSpace *btotal
     struct statfs      sfs;
 #endif /*ultrix*/
 
-
     if ( statfs( vol->v_path, &sfs ) < 0 ) {
         LOG(log_error, logtype_afpd, "ustatfs_getvolspace unable to stat %s", vol->v_path);
         return( AFPERR_PARAM );
index 41d8ba45657b0514afe185bcf63e0bdcdc3e348c..f50354e047acfd36331549c3850f1b09cd563075 100644 (file)
@@ -1458,9 +1458,9 @@ static long long int get_tm_bandsize(const char *path)
     char buf[512];
     long long int bandsize = -1;
 
-    EC_NULL_LOGSTR(file = fopen(path, "r"),
-                   "get_tm_bandsize(\"%s\"): %s",
-                   path, strerror(errno));
+    EC_NULL_LOGSTR( file = fopen(path, "r"),
+                    "get_tm_bandsize(\"%s\"): %s",
+                    path, strerror(errno) );
 
     while (fgets(buf, sizeof(buf), file) != NULL) {
         if (strstr(buf, "band-size") == NULL)
@@ -1493,7 +1493,7 @@ static long long int get_tm_bands(const char *path)
     DIR *dir = NULL;
     const struct dirent *entry;
 
-    EC_NULL(dir = opendir(path));
+    EC_NULL( dir = opendir(path) );
 
     while ((entry = readdir(dir)) != NULL)
         count++;
@@ -1518,15 +1518,19 @@ EC_CLEANUP:
  * 4) readdir "\1.sparsebundle/bands/" counting files
  * 5) calculate used size as: (file_count - 1) * band-size
  *
- * The result is cached in volume->v_tm_cachetime for TM_USED_CACHETIME secounds.
- * The cached value volume->v_tm_cachetime is updated by volume->v_appended. The latter
- * is increased by X every time the client appends X bytes to a file (in fork.c).
+ * The result of the calculation is returned in "volume->v_tm_used".
+ * "volume->v_appended" gets reset to 0.
+ * "volume->v_tm_cachetime" is updated with the current time from time(NULL).
+ *
+ * "volume->v_tm_used" is cached for TM_USED_CACHETIME seconds and updated by
+ * "volume->v_appended". The latter is increased by X every time the client
+ * appends X bytes to a file (in fork.c).
  *
  * @param vol     (rw) volume to calculate
- * @return             Estimated used size in bytes, -1 on error
+ * @return             0 on success, -1 on error
  */
 #define TM_USED_CACHETIME 60    /* cache for 60 seconds */
-static VolSpace get_tm_used(struct vol *vol)
+static int get_tm_used(struct vol * restrict vol)
 {
     EC_INIT;
     long long int bandsize;
@@ -1543,48 +1547,51 @@ static VolSpace get_tm_used(struct vol *vol)
     if (vol->v_tm_cachetime
         && ((vol->v_tm_cachetime + TM_USED_CACHETIME) >= now)) {
         if (vol->v_tm_used == -1)
-            return -1;
+            EC_FAIL;
         vol->v_tm_used += vol->v_appended;
         vol->v_appended = 0;
-        LOG(log_debug, logtype_afpd, "getused(%s): used(cached): %jd", vol->v_path, (intmax_t)vol->v_tm_used);
-        return vol->v_tm_used;
+        LOG(log_error, logtype_afpd, "getused(\"%s\"): cached: %" PRIu64 " bytes",
+            vol->v_path, vol->v_tm_used);
+        return 0;
     }
 
     vol->v_tm_cachetime = now;
 
-    EC_NULL(dir = opendir(vol->v_path));
+    EC_NULL( dir = opendir(vol->v_path) );
 
     while ((entry = readdir(dir)) != NULL) {
         if (((p = strstr(entry->d_name, "sparsebundle")) != NULL)
             && (strlen(entry->d_name) == (p + strlen("sparsebundle") - entry->d_name))) {
 
-            EC_NULL_LOG(infoplist = bformat("%s/%s/%s", vol->v_path, entry->d_name, "Info.plist"));
+            EC_NULL_LOG( infoplist = bformat("%s/%s/%s", vol->v_path, entry->d_name, "Info.plist") );
             
             if ((bandsize = get_tm_bandsize(cfrombstr(infoplist))) == -1)
                 continue;
 
-            EC_NULL_LOG(bandsdir = bformat("%s/%s/%s/", vol->v_path, entry->d_name, "bands"));
+            EC_NULL_LOG( bandsdir = bformat("%s/%s/%s/", vol->v_path, entry->d_name, "bands") );
 
             if ((links = get_tm_bands(cfrombstr(bandsdir))) == -1)
                 continue;
 
             used += (links - 1) * bandsize;
-            LOG(log_debug, logtype_afpd, "getused: %s, used: %jd", cfrombstr(bandsdir), (intmax_t)used);
+            LOG(log_debug, logtype_afpd, "getused(\"%s\"): bands: %" PRIu64 " bytes",
+                cfrombstr(bandsdir), used);
         }
     }
 
-EC_CLEANUP:
-    if (ret != 0)
-        used = -1;
     vol->v_tm_used = used;
+
+EC_CLEANUP:
     if (infoplist)
         bdestroy(infoplist);
     if (bandsdir)
         bdestroy(bandsdir);
     if (dir)
         closedir(dir);
-    LOG(log_debug, logtype_afpd, "getused(%s), used: %jd", vol->v_path, (intmax_t)used);
-    return used;
+
+    LOG(log_error, logtype_afpd, "getused(\"%s\"): %" PRIu64 " bytes", vol->v_path, vol->v_tm_used);
+
+    EC_EXIT;
 }
 
 static int getvolspace(struct vol *vol,
@@ -1617,13 +1624,12 @@ static int getvolspace(struct vol *vol,
         return( rc );
     }
 
-#define min(a,b)    ((a)<(b)?(a):(b))
 #ifndef NO_QUOTA_SUPPORT
     if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_UQUOTA ) {
         if ( uquota_getvolspace( vol, &qfree, &qtotal, *bsize ) == AFP_OK ) {
             vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_UQUOTA;
-            *xbfree = min(*xbfree, qfree);
-            *xbtotal = min( *xbtotal, qtotal);
+            *xbfree = MIN(*xbfree, qfree);
+            *xbtotal = MIN(*xbtotal, qtotal);
             goto getvolspace_done;
         }
     }
@@ -1635,15 +1641,16 @@ getvolspace_done:
         if ((used = get_tm_used(vol)) == -1)
             return AFPERR_MISC;
 
-        *xbtotal = min(*xbtotal, (vol->v_limitsize * 1024 * 1024));
-        *xbfree = min(*xbfree, *xbtotal < used ? 0 : *xbtotal - used);
+        *xbtotal = MIN(*xbtotal, (vol->v_limitsize * 1024 * 1024));
+        *xbfree = MIN(*xbfree, *xbtotal < used ? 0 : *xbtotal - used);
 
-        LOG(log_debug, logtype_afpd, "volparams: total: %jd, used: %jd, free: %jd",
-            (intmax_t)(*xbtotal), (intmax_t)used, (intmax_t)(*xbfree));
+        LOG(log_error, logtype_afpd,
+            "volparams: total: %" PRIu64 ", used: %" PRIu64 ", free: %" PRIu64 " bytes",
+            *xbtotal, used, *xbfree);
     }
 
-    *bfree = min( *xbfree, maxsize);
-    *btotal = min( *xbtotal, maxsize);
+    *bfree = MIN(*xbfree, maxsize);
+    *btotal = MIN(*xbtotal, maxsize);
     return( AFP_OK );
 }
 
index 4237a3f5b623a27b5b5a860ce084d744ab3dad7b..af2b411c625ca6b07f8203798d5ccbcd12d36c10 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: volume.h,v 1.16 2010/03/31 09:47:32 franklahm Exp $
- *
  * Copyright (c) 1990,1994 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
  */
@@ -8,9 +6,10 @@
 #ifndef ATALK_VOLUME_H
 #define ATALK_VOLUME_H 1
 
+#include <stdint.h>
 #include <sys/cdefs.h>
 #include <sys/types.h>
-#include <netatalk/endian.h>
+// #include <netatalk/endian.h>
 
 #include <atalk/unicode.h>
 #include <atalk/cnid.h>
@@ -20,7 +19,7 @@
 #define AFPVOL_U8MNAMELEN   255 /* AFP3 sepc */
 #define AFPVOL_MACNAMELEN    27 /* AFP2 spec */
 
-typedef off_t VolSpace;
+typedef uint64_t VolSpace;
 
 struct vol {
     struct vol      *v_next;
@@ -65,9 +64,9 @@ struct vol {
     char            *v_gvs;
     void            *v_nfsclient;
     int             v_nfs;
-    off_t           v_tm_used;  /* used bytes on a TM volume */
+    VolSpace        v_tm_used;  /* used bytes on a TM volume */
     time_t          v_tm_cachetime; /* time at which v_tm_used was calculated last */
-    off_t           v_appended; /* amount of data appended to files */
+    VolSpace        v_appended; /* amount of data appended to files */
     
     /* only when opening/closing volumes or in error */
     int             v_casefold;
index 1d69dc61d3cf79a7264f528262871d0a41f78942..6aabe036499e4fcdd05b3643acd7743de635f69d 100644 (file)
@@ -139,6 +139,8 @@ be treated normally any longer\&. Its only aim was to temporarely share eg\&. FA
 volsizelimit:\fIsize in MiB\fR
 .RS 4
 Useful for TimeMachine: limits the reported volume size, thus preventing TM from using the whole real disk space for backup\&. Example: "volsizelimit:1000" would limit the reported disk space to 1 GB\&.
+\fBIMPORTANT: \fR
+This is an approximated calculation taking into accout the contents of TM sparsebundle images\&. Therefor you MUST NOT use this volume to store other content when using this option, because it would NOT be accounted\&. The calculation works by reading the band size from the Info\&.plist XML file of the sparsebundle, reading the bands/ directory counting the number of band files, and then multiplying one with the other\&.
 .RE
 .PP
 allow:\fI[users/groups]\fR