summaryrefslogtreecommitdiffstats
path: root/utils/nfsdcld/sqlite.c
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2012-04-26 11:48:52 -0400
committerSteve Dickson <steved@redhat.com>2012-04-26 13:25:04 -0400
commit09d9011c66e518ca7fd01d41607845b940f58c8f (patch)
treeb4cddb31438f80171f5f8053d06da76d1168fd12 /utils/nfsdcld/sqlite.c
parent1b0d2b29df2e089bbcabc37a4cd716a448d48a5e (diff)
downloadnfs-utils-09d9011c66e518ca7fd01d41607845b940f58c8f.tar.gz
nfs-utils-09d9011c66e518ca7fd01d41607845b940f58c8f.tar.xz
nfs-utils-09d9011c66e518ca7fd01d41607845b940f58c8f.zip
nfsdcld: add function to remove unreclaimed client records
This should remove any client record that has a timestamp prior to the given time. Eventually, this call will need to be made cluster aware when this is run in a clustered configuration. For now, this is only suitable for single-host configurations. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils/nfsdcld/sqlite.c')
-rw-r--r--utils/nfsdcld/sqlite.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/utils/nfsdcld/sqlite.c b/utils/nfsdcld/sqlite.c
index 01bba1a..9e35774 100644
--- a/utils/nfsdcld/sqlite.c
+++ b/utils/nfsdcld/sqlite.c
@@ -38,6 +38,7 @@
#include "config.h"
#endif /* HAVE_CONFIG_H */
+#include <dirent.h>
#include <errno.h>
#include <event.h>
#include <stdbool.h>
@@ -360,3 +361,30 @@ out_err:
sqlite3_finalize(stmt);
return ret;
}
+
+/*
+ * remove any client records that were not reclaimed since grace_start.
+ */
+int
+sqlite_remove_unreclaimed(time_t grace_start)
+{
+ int ret;
+ char *err = NULL;
+
+ ret = snprintf(buf, sizeof(buf), "DELETE FROM clients WHERE time < %ld",
+ grace_start);
+ if (ret < 0) {
+ return ret;
+ } else if ((size_t)ret >= sizeof(buf)) {
+ ret = -EINVAL;
+ return ret;
+ }
+
+ ret = sqlite3_exec(dbh, buf, NULL, NULL, &err);
+ if (ret != SQLITE_OK)
+ xlog(L_ERROR, "%s: delete failed: %s", __func__, err);
+
+ xlog(D_GENERAL, "%s: returning %d", __func__, ret);
+ sqlite3_free(err);
+ return ret;
+}