]> arthur.barton.de Git - netatalk.git/commitdiff
Only add appended data written to files to the TM used size
authorFrank Lahm <franklahm@googlemail.com>
Wed, 23 Nov 2011 18:10:05 +0000 (19:10 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 23 Nov 2011 18:10:05 +0000 (19:10 +0100)
etc/afpd/fork.c
etc/afpd/volume.c
include/atalk/volume.h

index 0c4956b82c8a85684f703631b4f4f3e8f1e3ce37..f4d513779d4b0188eaa908d89cd6b8a2c2636e1b 100644 (file)
@@ -1183,7 +1183,7 @@ static ssize_t write_file(struct ofork *ofork, int eid,
 static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen, int is64)
 {
     struct ofork       *ofork;
-    off_t              offset, saveoff, reqcount;
+    off_t           offset, saveoff, reqcount, oldsize, newsize;
     int                        endflag, eid, xlate = 0, err = AFP_OK;
     u_int16_t          ofrefnum;
     ssize_t             cc;
@@ -1223,8 +1223,9 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
         goto afp_write_err;
     }
 
+    oldsize = ad_size(ofork->of_ad, eid);
     if (endflag)
-        offset += ad_size(ofork->of_ad, eid);
+        offset += oldsize;
 
     /* handle bogus parameters */
     if (reqcount < 0 || offset < 0) {
@@ -1232,6 +1233,8 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
         goto afp_write_err;
     }
 
+    newsize = ((offset + reqcount) > oldsize) ? (offset + reqcount) : oldsize;
+
     /* offset can overflow on 64-bit capable filesystems.
      * report disk full if that's going to happen. */
      if (sum_neg(is64, offset, reqcount)) {
@@ -1342,7 +1345,8 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
     ofork->of_flags |= AFPFORK_MODIFIED;
 
     /* update write count */
-    ofork->of_vol->v_written += reqcount;
+    ofork->of_vol->v_appended += (newsize > oldsize) ? (newsize - oldsize) : 0;
+    LOG(log_error, logtype_afpd, "write_file: %jd", (intmax_t)((newsize > oldsize) ? (newsize - oldsize) : 0));
 
     *rbuflen = set_off_t (offset, rbuf, is64);
     return( AFP_OK );
index 7f8b1a535a34028890ee1c790099b4a0af1b1ed2..fcc377abf09f431d2a67f0feedd448d1bcc302f8 100644 (file)
@@ -1458,8 +1458,6 @@ static long long int get_tm_bandsize(const char *path)
     char buf[512];
     long long int bandsize = -1;
 
-    LOG(log_error, logtype_afpd, "get_tm_bandsize(\"%s\")", path);
-
     EC_NULL_LOGSTR(file = fopen(path, "r"),
                    "get_tm_bandsize(\"%s\"): %s",
                    path, strerror(errno));
@@ -1478,6 +1476,7 @@ static long long int get_tm_bandsize(const char *path)
 EC_CLEANUP:
     if (file)
         fclose(file);
+    LOG(log_debug, logtype_afpd, "get_tm_bandsize(\"%s\"): bandsize: %lld", path, bandsize);
     return bandsize;
 }
 
@@ -1520,8 +1519,8 @@ EC_CLEANUP:
  * 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_written. The latter
- * is increased by X every time the client writes X bytes into a file (in fork.c).
+ * 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).
  *
  * @param vol     (rw) volume to calculate
  * @return             Estimated used size in bytes, -1 on error
@@ -1545,9 +1544,9 @@ static VolSpace get_tm_used(struct vol *vol)
         && ((vol->v_tm_cachetime + TM_USED_CACHETIME) >= now)) {
         if (vol->v_tm_used == -1)
             return -1;
-        vol->v_tm_used += vol->v_written;
-        vol->v_written = 0;
-        LOG(log_error, logtype_afpd, "getused(%s): used(cached): %jd", vol->v_path, (intmax_t)vol->v_tm_used);
+        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;
     }
 
@@ -1558,24 +1557,19 @@ static VolSpace get_tm_used(struct vol *vol)
     while ((entry = readdir(dir)) != NULL) {
         if (((p = strstr(entry->d_name, "sparsebundle")) != NULL)
             && (strlen(entry->d_name) == (p + strlen("sparsebundle") - entry->d_name))) {
-            LOG(log_error, logtype_afpd, "getused(\"%s\"): %s", vol->v_path, entry->d_name);
 
             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;
 
-            LOG(log_error, logtype_afpd, "getused: %s, bandsize: %lld", cfrombstr(infoplist), bandsize);
-
             EC_NULL_LOG(bandsdir = bformat("%s/%s/%s/", vol->v_path, entry->d_name, "bands"));
 
             if ((links = get_tm_bands(cfrombstr(bandsdir))) == -1)
                 continue;
 
-            LOG(log_error, logtype_afpd, "getused: %s, links: %ld", cfrombstr(bandsdir), links);
-
             used += (links - 1) * bandsize;
-            LOG(log_error, logtype_afpd, "getused: %s, used: %jd", cfrombstr(bandsdir), (intmax_t)used);
+            LOG(log_debug, logtype_afpd, "getused: %s, used: %jd", cfrombstr(bandsdir), (intmax_t)used);
         }
     }
 
@@ -1589,7 +1583,7 @@ EC_CLEANUP:
         bdestroy(bandsdir);
     if (dir)
         closedir(dir);
-    LOG(log_error, logtype_afpd, "getused(%s), used: %jd", vol->v_path, (intmax_t)used);
+    LOG(log_debug, logtype_afpd, "getused(%s), used: %jd", vol->v_path, (intmax_t)used);
     return used;
 }
 
@@ -1622,8 +1616,6 @@ static int getvolspace(struct vol *vol,
     if (( rc = ustatfs_getvolspace( vol, xbfree, xbtotal, bsize)) != AFP_OK ) {
         return( rc );
     }
-    LOG(log_error, logtype_afpd, "volparams: total: %jd, free: %jd",
-        (intmax_t)(*xbtotal), (intmax_t)(*xbfree));
 
 #define min(a,b)    ((a)<(b)?(a):(b))
 #ifndef NO_QUOTA_SUPPORT
@@ -1642,8 +1634,6 @@ getvolspace_done:
     if (vol->v_limitsize) {
         if ((used = get_tm_used(vol)) == -1)
             return AFPERR_MISC;
-        LOG(log_error, logtype_afpd, "volparams: total: %jd, used: %jd, free: %jd",
-            (intmax_t)(*xbtotal), (intmax_t)used, (intmax_t)(*xbfree));
 
         *xbtotal = min(*xbtotal, (vol->v_limitsize * 1024 * 1024));
         *xbfree = min(*xbfree, *xbtotal < used ? 0 : *xbtotal - used);
@@ -1668,7 +1658,7 @@ void vol_fce_tm_event(void)
         last = now;
         for ( ; vol; vol = vol->v_next ) {
             if (vol->v_flags & AFPVOL_TM)
-                (void)fce_register_tm_size(vol->v_path, vol->v_tm_used + vol->v_written);
+                (void)fce_register_tm_size(vol->v_path, vol->v_tm_used + vol->v_appended);
         }
     }
 }
index 84a57c1d8a26b510cf7c4d09d247d2b556fba822..4237a3f5b623a27b5b5a860ce084d744ab3dad7b 100644 (file)
@@ -67,7 +67,7 @@ struct vol {
     int             v_nfs;
     off_t           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_written;  /* amount of data written in afp_write, reset every time a FCE_TM_SIZE event is sent */
+    off_t           v_appended; /* amount of data appended to files */
     
     /* only when opening/closing volumes or in error */
     int             v_casefold;