summaryrefslogtreecommitdiffstats
path: root/utils/nfsdcld/nfsdcld.c
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2012-04-26 11:43:30 -0400
committerSteve Dickson <steved@redhat.com>2012-04-26 13:25:04 -0400
commit3e859abefffafd8718b5f1f76da7b129fc18e281 (patch)
tree7e5fe58c202e3f3706735a20580ca58c88ba898f /utils/nfsdcld/nfsdcld.c
parentdfebe7f4f25a12b615195f339192fa8837d9b5c9 (diff)
downloadnfs-utils-3e859abefffafd8718b5f1f76da7b129fc18e281.tar.gz
nfs-utils-3e859abefffafd8718b5f1f76da7b129fc18e281.tar.xz
nfs-utils-3e859abefffafd8718b5f1f76da7b129fc18e281.zip
nfsdcld: add routines for a sqlite backend database
Rather than roll our own "storage engine", use sqlite instead. It fits the bill nicely as it does: - durable on-disk storage - the ability to constrain record uniqueness - a facility for collating and searching the host records ...it does add a build dependency to nfs-utils, but almost all modern distros provide those packages. The current incarnation of this code dynamically links against a provided sqlite library, but we could also consider including their single-file "amalgamation" to reduce dependencies (though with all the caveats that that entails). Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils/nfsdcld/nfsdcld.c')
-rw-r--r--utils/nfsdcld/nfsdcld.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/utils/nfsdcld/nfsdcld.c b/utils/nfsdcld/nfsdcld.c
index 9fab2c3..c58801c 100644
--- a/utils/nfsdcld/nfsdcld.c
+++ b/utils/nfsdcld/nfsdcld.c
@@ -61,6 +61,7 @@ static struct option longopts[] =
{ "foreground", 0, NULL, 'F' },
{ "debug", 0, NULL, 'd' },
{ "pipe", 1, NULL, 'p' },
+ { "storagedir", 1, NULL, 's' },
{ NULL, 0, 0, 0 },
};
@@ -70,7 +71,7 @@ static void cldcb(int UNUSED(fd), short which, void *data);
static void
usage(char *progname)
{
- printf("Usage: %s [ -hFd ] [ -p pipe ]\n", progname);
+ printf("%s [ -hFd ] [ -p pipe ] [ -s dir ]\n", progname);
}
static int
@@ -144,15 +145,16 @@ cld_create(struct cld_client *clnt)
ssize_t bsize, wsize;
struct cld_msg *cmsg = &clnt->cl_msg;
- xlog(D_GENERAL, "%s: create client record", __func__);
+ xlog(D_GENERAL, "%s: create client record.", __func__);
- /* FIXME: create client record on storage here */
+ ret = sqlite_insert_client(cmsg->cm_u.cm_name.cn_id,
+ cmsg->cm_u.cm_name.cn_len);
- /* set up reply */
- cmsg->cm_status = 0;
+ 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",
@@ -210,6 +212,7 @@ main(int argc, char **argv)
int rc = 0;
bool foreground = false;
char *progname;
+ char *storagedir = NULL;
struct cld_client clnt;
memset(&clnt, 0, sizeof(clnt));
@@ -225,7 +228,7 @@ main(int argc, char **argv)
xlog_stderr(1);
/* process command-line options */
- while ((arg = getopt_long(argc, argv, "hdFp:", longopts,
+ while ((arg = getopt_long(argc, argv, "hdFp:s:", longopts,
NULL)) != EOF) {
switch (arg) {
case 'd':
@@ -237,6 +240,9 @@ main(int argc, char **argv)
case 'p':
pipepath = optarg;
break;
+ case 's':
+ storagedir = optarg;
+ break;
default:
usage(progname);
return 0;
@@ -256,6 +262,11 @@ main(int argc, char **argv)
}
/* set up storage db */
+ rc = sqlite_maindb_init(storagedir);
+ if (rc) {
+ xlog(L_ERROR, "Failed to open main database: %d", rc);
+ goto out;
+ }
/* set up event handler */
rc = cld_pipe_init(&clnt);