]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
nfsdcld: add function to remove unreclaimed client records
authorJeff Layton <jlayton@redhat.com>
Thu, 26 Apr 2012 15:48:52 +0000 (11:48 -0400)
committerSteve Dickson <steved@redhat.com>
Thu, 26 Apr 2012 17:25:04 +0000 (13:25 -0400)
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>
utils/nfsdcld/nfsdcld.c
utils/nfsdcld/sqlite.c
utils/nfsdcld/sqlite.h

index 2dfd7ecc7d9c08765fa92a9afc4aaf34297fa224..2d118681abbb5f11809898a072cbea1a5d944bf1 100644 (file)
@@ -231,6 +231,37 @@ cld_check(struct cld_client *clnt)
        }
 }
 
        }
 }
 
+static void
+cld_gracedone(struct cld_client *clnt)
+{
+       int ret;
+       ssize_t bsize, wsize;
+       struct cld_msg *cmsg = &clnt->cl_msg;
+
+       xlog(D_GENERAL, "%s: grace done. cm_gracetime=%ld", __func__,
+                       cmsg->cm_u.cm_gracetime);
+
+       ret = sqlite_remove_unreclaimed(cmsg->cm_u.cm_gracetime);
+
+       /* set up reply: downcall with 0 status */
+       cmsg->cm_status = ret ? -EREMOTEIO : ret;
+
+       bsize = sizeof(*cmsg);
+
+       xlog(D_GENERAL, "Doing downcall with status %d", cmsg->cm_status);
+       wsize = atomicio((void *)write, clnt->cl_fd, cmsg, bsize);
+       if (wsize != bsize) {
+               xlog(L_ERROR, "%s: problem writing to cld pipe (%ld): %m",
+                        __func__, wsize);
+               ret = cld_pipe_open(clnt);
+               if (ret) {
+                       xlog(L_FATAL, "%s: unable to reopen pipe: %d",
+                                       __func__, ret);
+                       exit(ret);
+               }
+       }
+}
+
 static void
 cldcb(int UNUSED(fd), short which, void *data)
 {
 static void
 cldcb(int UNUSED(fd), short which, void *data)
 {
@@ -265,6 +296,9 @@ cldcb(int UNUSED(fd), short which, void *data)
        case Cld_Check:
                cld_check(clnt);
                break;
        case Cld_Check:
                cld_check(clnt);
                break;
+       case Cld_GraceDone:
+               cld_gracedone(clnt);
+               break;
        default:
                xlog(L_WARNING, "%s: command %u is not yet implemented",
                                __func__, cmsg->cm_cmd);
        default:
                xlog(L_WARNING, "%s: command %u is not yet implemented",
                                __func__, cmsg->cm_cmd);
index 01bba1a13c276d80aef95a0af7ea43e3ade6cd6b..9e357741fee7deef3b83ed4bbed50389322622fe 100644 (file)
@@ -38,6 +38,7 @@
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
 #include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#include <dirent.h>
 #include <errno.h>
 #include <event.h>
 #include <stdbool.h>
 #include <errno.h>
 #include <event.h>
 #include <stdbool.h>
@@ -360,3 +361,30 @@ out_err:
        sqlite3_finalize(stmt);
        return ret;
 }
        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;
+}
index 59ebd723f5ea13c61e7617f7d7f70383fd9c9804..c85e7d683c0a2c763a1efe872c5e41902fd9c7b8 100644 (file)
@@ -24,5 +24,6 @@ int sqlite_maindb_init(char *topdir);
 int sqlite_insert_client(const unsigned char *clname, const size_t namelen);
 int sqlite_remove_client(const unsigned char *clname, const size_t namelen);
 int sqlite_check_client(const unsigned char *clname, const size_t namelen);
 int sqlite_insert_client(const unsigned char *clname, const size_t namelen);
 int sqlite_remove_client(const unsigned char *clname, const size_t namelen);
 int sqlite_check_client(const unsigned char *clname, const size_t namelen);
+int sqlite_remove_unreclaimed(const time_t grace_start);
 
 #endif /* _SQLITE_H */
 
 #endif /* _SQLITE_H */