From: Jeff Layton <jlayton@redhat.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH v5 4/9] nfsdcld: add remove functionality
Date: Wed, 1 Feb 2012 10:44:51 -0500 [thread overview]
Message-ID: <1328111096-28430-5-git-send-email-jlayton@redhat.com> (raw)
In-Reply-To: <1328111096-28430-1-git-send-email-jlayton@redhat.com>
Allow the kernel to ask for removal of a client record.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
utils/nfsdcld/nfsdcld.c | 34 ++++++++++++++++++++++++++++++++++
utils/nfsdcld/sqlite.c | 36 ++++++++++++++++++++++++++++++++++++
utils/nfsdcld/sqlite.h | 1 +
3 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/utils/nfsdcld/nfsdcld.c b/utils/nfsdcld/nfsdcld.c
index 15746e6..ce8355a 100644
--- a/utils/nfsdcld/nfsdcld.c
+++ b/utils/nfsdcld/nfsdcld.c
@@ -171,6 +171,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)
{
ssize_t len;
@@ -198,6 +229,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);
diff --git a/utils/nfsdcld/sqlite.c b/utils/nfsdcld/sqlite.c
index f70568e..a198c34 100644
--- a/utils/nfsdcld/sqlite.c
+++ b/utils/nfsdcld/sqlite.c
@@ -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;
+}
diff --git a/utils/nfsdcld/sqlite.h b/utils/nfsdcld/sqlite.h
index ba4c213..425f5ba 100644
--- a/utils/nfsdcld/sqlite.h
+++ b/utils/nfsdcld/sqlite.h
@@ -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 */
--
1.7.7.6
next prev parent reply other threads:[~2012-02-01 15:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-01 15:44 [PATCH v5 0/9] nfsdcld: add a daemon to track NFSv4 client names on stable storage Jeff Layton
2012-02-01 15:44 ` [PATCH v5 1/9] nfsdcld: add client tracking daemon stub Jeff Layton
2012-04-16 14:06 ` Steve Dickson
2012-04-16 14:23 ` Jeff Layton
2012-04-16 15:14 ` Steve Dickson
2012-04-16 15:42 ` Jeff Layton
2012-04-16 16:44 ` Steve Dickson
2012-02-01 15:44 ` [PATCH v5 2/9] nfsdcld: add autoconf goop for sqlite Jeff Layton
2012-02-01 15:44 ` [PATCH v5 3/9] nfsdcld: add routines for a sqlite backend database Jeff Layton
2012-02-01 15:44 ` Jeff Layton [this message]
2012-02-01 15:44 ` [PATCH v5 5/9] nfsdcld: add check/update functionality Jeff Layton
2012-02-01 15:44 ` [PATCH v5 6/9] nfsdcld: add function to remove unreclaimed client records Jeff Layton
2012-02-01 15:44 ` [PATCH v5 7/9] nfsdcld: make it watch for inotify events in the containing directory Jeff Layton
2012-02-01 15:44 ` [PATCH v5 8/9] nfsdcld: add a manpage for nfsdcld Jeff Layton
2012-02-01 15:44 ` [PATCH v5 9/9] nfsdcld: update the README Jeff Layton
2012-04-26 17:38 ` [PATCH v5 0/9] nfsdcld: add a daemon to track NFSv4 client names on stable storage Steve Dickson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1328111096-28430-5-git-send-email-jlayton@redhat.com \
--to=jlayton@redhat.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).