]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
nfsdcld: add remove functionality
authorJeff Layton <jlayton@redhat.com>
Thu, 26 Apr 2012 15:46:14 +0000 (11:46 -0400)
committerSteve Dickson <steved@redhat.com>
Thu, 26 Apr 2012 17:25:04 +0000 (13:25 -0400)
Allow the kernel to ask for removal of a client record.

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 c58801c4675d5a739cf2b6233f4e0d3bcdf9a970..a6c5239976d43e49e02baa4e23e58558591810af 100644 (file)
@@ -168,6 +168,37 @@ cld_create(struct cld_client *clnt)
        }
 }
 
+static void
+cld_remove(struct cld_client *clnt)
+{
+       int ret;
+       ssize_t bsize, wsize;
+       struct cld_msg *cmsg = &clnt->cl_msg;
+
+       xlog(D_GENERAL, "%s: remove client record.", __func__);
+
+       ret = sqlite_remove_client(cmsg->cm_u.cm_name.cn_id,
+                                  cmsg->cm_u.cm_name.cn_len);
+
+       cmsg->cm_status = ret ? -EREMOTEIO : ret;
+
+       bsize = sizeof(*cmsg);
+
+       xlog(D_GENERAL, "%s: downcall with status %d", __func__,
+                       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)
 {
@@ -196,6 +227,9 @@ cldcb(int UNUSED(fd), short which, void *data)
        case Cld_Create:
                cld_create(clnt);
                break;
+       case Cld_Remove:
+               cld_remove(clnt);
+               break;
        default:
                xlog(L_WARNING, "%s: command %u is not yet implemented",
                                __func__, cmsg->cm_cmd);
index f70568e1b4726df61aba872269ccdfc7e4aba97e..a198c34aa6537737a350da2081a0819007482336 100644 (file)
@@ -251,3 +251,39 @@ out_err:
        sqlite3_finalize(stmt);
        return ret;
 }
+
+/* Remove a client record */
+int
+sqlite_remove_client(const unsigned char *clname, const size_t namelen)
+{
+       int ret;
+       sqlite3_stmt *stmt = NULL;
+
+       ret = sqlite3_prepare_v2(dbh, "DELETE FROM clients WHERE id==?", -1,
+                                &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               xlog(L_ERROR, "%s: statement prepare failed: %s",
+                               __func__, sqlite3_errmsg(dbh));
+               goto out_err;
+       }
+
+       ret = sqlite3_bind_blob(stmt, 1, (const void *)clname, namelen,
+                               SQLITE_STATIC);
+       if (ret != SQLITE_OK) {
+               xlog(L_ERROR, "%s: bind blob failed: %s", __func__,
+                               sqlite3_errmsg(dbh));
+               goto out_err;
+       }
+
+       ret = sqlite3_step(stmt);
+       if (ret == SQLITE_DONE)
+               ret = SQLITE_OK;
+       else
+               xlog(L_ERROR, "%s: unexpected return code from delete: %d",
+                               __func__, ret);
+
+out_err:
+       xlog(D_GENERAL, "%s: returning %d", __func__, ret);
+       sqlite3_finalize(stmt);
+       return ret;
+}
index ba4c213d43ccdea8ce0757284e4c0be8d747b4b4..425f5bab67888c6ea8c0543a81be9d35ee1844d2 100644 (file)
@@ -22,5 +22,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);
 
 #endif /* _SQLITE_H */