#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"
break;
}
pending_request(dsi);
+
+ vol_fce_tm_event();
}
/* error */
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);
/* 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 );
#include <atalk/bstradd.h>
#include <atalk/ftw.h>
#include <atalk/globals.h>
+#include <atalk/fce_api.h>
#ifdef CNID_DB
#include <atalk/cnid.h>
* 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;
) {
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);
}
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);
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
#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 *,
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);
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 */