]> arthur.barton.de Git - netatalk.git/commitdiff
Count the amount of data written in afp_write and use it to adjust the cached TM...
authorFrank Lahm <franklahm@googlemail.com>
Wed, 1 Jun 2011 09:34:12 +0000 (11:34 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 1 Jun 2011 09:34:12 +0000 (11:34 +0200)
etc/afpd/afp_dsi.c
etc/afpd/filedir.c
etc/afpd/fork.c
etc/afpd/volume.c
etc/afpd/volume.h
include/atalk/volume.h

index 1d59e118f509023f41caa35b90b35472530f7408..0e9a21640ef303a656bdb0b0851eac686f44aa14 100644 (file)
 #endif /* HAVE_SYS_STAT_H */
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <atalk/logger.h>
 #include <setjmp.h>
+#include <time.h>
 
+#include <atalk/logger.h>
 #include <atalk/dsi.h>
 #include <atalk/compat.h>
 #include <atalk/util.h>
 #include <atalk/uuid.h>
 #include <atalk/paths.h>
 #include <atalk/server_ipc.h>
+#include <atalk/fce_api.h>
 
 #include <atalk/globals.h>
 #include "switch.h"
@@ -685,6 +687,8 @@ void afp_over_dsi(AFPObj *obj)
             break;
         }
         pending_request(dsi);
+
+        vol_fce_tm_event();
     }
 
     /* error */
index 7166c125d36c8af3cae56270fec3924a8e31037e..16c329ab72d6b38c7580d416b8fe6c1e57ed88b5 100644 (file)
@@ -624,9 +624,13 @@ int afp_delete(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size
         if (s_path->st_valid && s_path->st_errno == ENOENT) {
             rc = AFPERR_NOOBJ;
         } else {
-            if ((rc = deletefile(vol, -1, upath, 1)) == AFP_OK)
+            if ((rc = deletefile(vol, -1, upath, 1)) == AFP_OK) {
                                fce_register_delete_file( s_path );
-
+                if (vol->v_tm_used < s_path->st.st_size)
+                    vol->v_tm_used = 0;
+                else 
+                    vol->v_tm_used -= s_path->st.st_size;
+            }
             struct dir *cachedfile;
             if ((cachedfile = dircache_search_by_name(vol, dir, upath, strlen(upath)))) {
                 dircache_remove(vol, cachedfile, DIRCACHE | DIDNAME_INDEX | QUEUE_INDEX);
index cf9d8b841b643289be6466225569801f70b11b34..00436dbc01ab8dd4f29e654e9fd533eea7c99ab7 100644 (file)
@@ -1339,6 +1339,9 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
     /* we have modified any fork, remember until close_fork */
     ofork->of_flags |= AFPFORK_MODIFIED;
 
+    /* update write count */
+    ofork->of_vol->v_written += reqcount;
+
     *rbuflen = set_off_t (offset, rbuf, is64);
     return( AFP_OK );
 
index 0c810b82bd43c43d0b2fd76f206ff0c04b372c4c..faf142c402bbe21c99029b135cfc3f23f8ed8a14 100644 (file)
@@ -51,6 +51,7 @@ char *strchr (), *strrchr ();
 #include <atalk/bstradd.h>
 #include <atalk/ftw.h>
 #include <atalk/globals.h>
+#include <atalk/fce_api.h>
 
 #ifdef CNID_DB
 #include <atalk/cnid.h>
@@ -1460,9 +1461,9 @@ static int getused_stat(const char *path,
  *       longer then 30 sec ago
  * 1c) - the last volume modification is less then 30 sec old
  *
- * @param vol     (r) volume to calculate
+ * @param vol     (rw) volume to calculate
  */
-static int getused(const struct vol *vol)
+static int getused(struct vol *vol)
 {
     static time_t vol_mtime = 0;
     int ret = 0;
@@ -1474,10 +1475,13 @@ static int getused(const struct vol *vol)
         ) {
         vol_mtime = now;
         getused_size = 0;
+        vol->v_written = 0;
         ret = nftw(vol->v_path, getused_stat, NULL, 20, FTW_PHYS); /* 2 */
         LOG(log_debug, logtype_afpd, "volparams: from nftw: %" PRIu64 " bytes",
             getused_size);
     } else {
+        getused_size += vol->v_written;
+        vol->v_written = 0;
         LOG(log_debug, logtype_afpd, "volparams: cached used: %" PRIu64 " bytes",
             getused_size);
     }
@@ -1534,6 +1538,7 @@ getvolspace_done:
             return AFPERR_MISC;
         LOG(log_debug, logtype_afpd, "volparams: used on volume: %" PRIu64 " bytes",
             getused_size);
+        vol->v_tm_used = getused_size;
 
         *xbtotal = min(*xbtotal, (vol->v_limitsize * 1024 * 1024));
         *xbfree = min(*xbfree, *xbtotal < getused_size ? 0 : *xbtotal - getused_size);
@@ -1544,6 +1549,22 @@ getvolspace_done:
     return( AFP_OK );
 }
 
+#define FCE_TM_DELTA 10  /* send notification every 10 seconds */
+void vol_fce_tm_event(void)
+{
+    static time_t last;
+    time_t now = time(NULL);
+    struct vol  *vol = Volumes;
+
+    if ((last + FCE_TM_DELTA) < now) {
+        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);
+        }
+    }
+}
+
 /* -----------------------
  * set volume creation date
  * avoid duplicate, well at least it tries
index 2339ca8cf855aeb98ff4db757abcdbd6ccdae6f8..eedc622bd275107758b7522e570f6e37eb278b4c 100644 (file)
 #include <atalk/unicode.h>
 #include <atalk/globals.h>
 
-#if 0
-#include "hash.h"
-#endif
-
 extern struct vol       *getvolbyvid (const u_int16_t);
 extern int              ustatfs_getvolspace (const struct vol *,
             VolSpace *, VolSpace *,
@@ -28,6 +24,7 @@ extern int              pollvoltime (AFPObj *);
 extern void             load_volumes (AFPObj *obj);
 extern const struct vol *getvolumes(void);
 extern void             unload_volumes_and_extmap(void);
+extern void             vol_fce_tm_event(void);
 
 /* FP functions */
 int afp_openvol      (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf,  size_t *rbuflen);
index 44cb6f6b5a7befa5302e8a971826f418c2813498..01de038d3c5ae19a09f2d42720e00597585156de 100644 (file)
@@ -65,7 +65,9 @@ struct vol {
     char            *v_gvs;
     void            *v_nfsclient;
     int             v_nfs;
-
+    uintmax_t       v_tm_used;  /* used bytes on a TM volume */
+    uintmax_t       v_written;  /* amount of data written in afp_write, reset every time a FCE_TM_SIZE event is sent */
+    
     /* only when opening/closing volumes or in error */
     int             v_casefold;
     char            *v_localname;   /* as defined in AppleVolumes.default */