api updates master
authorroot <root@hsm1n1.VSOFS1.COM>
Tue, 26 Aug 2008 10:45:07 +0000 (20:45 +1000)
committerroot <root@hsm1n1.VSOFS1.COM>
Tue, 26 Aug 2008 10:45:07 +0000 (20:45 +1000)
hacksm_ls.c
hacksm_migrate.c
hacksmd.c
store.h
store_file.c

index bb582c173b8be7d31f54cc5841164f5956a4e6ea..40aaa446b10af8e57d1778eae8ed03f5e30fd6d5 100644 (file)
@@ -60,6 +60,11 @@ static void hsm_init(void)
                printf("Unable to open HSM store - %s\n", strerror(errno));
                exit(1);
        }
+
+       if (hsm_store_connect(store_ctx, "/gpfs") != 0) {
+               printf("Failed to connect to HSM store\n");
+               exit(1);
+       }
 }
 
 
index 1aacfe66311842a23a07d4854125ffa5ab43b374..61e7901f49297fc402af25447cd2df17a624dc5a 100644 (file)
@@ -57,6 +57,11 @@ static void hsm_init(void)
                printf("Unable to open HSM store - %s\n", strerror(errno));
                exit(1);
        }
+
+       if (hsm_store_connect(store_ctx, "/gpfs") != 0) {
+               printf("Failed to connect to HSM store\n");
+               exit(1);
+       }
 }
 
 /*
@@ -168,7 +173,7 @@ static int hsm_migrate(const char *path)
        /* read the file data and store it away */
        ofs = 0;
        while ((ret = dm_read_invis(dmapi.sid, hanp, hlen, dmapi.token, ofs, sizeof(buf), buf)) > 0) {
-               if (hsm_store_write(handle, buf, ret) != ret) {
+               if (hsm_store_write(handle, buf, ret) != 0) {
                        printf("Failed to write to store for %s - %s\n", path, strerror(errno));
                        hsm_store_close(handle);
                        hsm_store_remove(store_ctx, st.st_dev, st.st_ino);
index 6c78367727cd729ae421681eb7e8c3f20468d613..d134d99d0065dc571da5bc8e6fafd175e38b711f 100644 (file)
--- a/hacksmd.c
+++ b/hacksmd.c
@@ -60,6 +60,11 @@ static void hsm_init(void)
                exit(1);
        }
 
+       if (hsm_store_connect(store_ctx, "/gpfs") != 0) {
+               printf("Failed to connect to HSM store\n");
+               exit(1);
+       }
+
        while ((ret = dm_init_service(&dmapi_version)) == -1) {
                if (errno != errcode) {
                        errcode = errno;
diff --git a/store.h b/store.h
index 91b30107843bba091fc2dd05c9be1c2db2b53c45..90493051955ca1027257419f898f8f3c1c4b4ccf 100644 (file)
--- a/store.h
+++ b/store.h
@@ -13,6 +13,17 @@ struct hsm_store_context *hsm_store_init(void);
 struct hsm_store_handle *hsm_store_open(struct hsm_store_context *,
                                        dev_t device, ino_t inode, bool readonly);
 
+/*
+  return an error message for the last failed operation
+ */
+const char *hsm_store_errmsg(struct hsm_store_context *ctx);
+
+
+/*
+  connect to the store
+ */
+int hsm_store_connect(struct hsm_store_context *ctx, const char *fsname);
+
 /*
   read from an open handle
  */
@@ -21,7 +32,7 @@ size_t hsm_store_read(struct hsm_store_handle *, uint8_t *buf, size_t n);
 /* 
    write to an open handle
  */
-size_t hsm_store_write(struct hsm_store_handle *, uint8_t *buf, size_t n);
+int hsm_store_write(struct hsm_store_handle *, uint8_t *buf, size_t n);
 
 /* 
    close a handle
index 3a8f162a11c84a2a8ff30f044f4d78a63fe91332..ac2411bbf0be7bebc14ac717879ed6f3f3aabd30 100644 (file)
@@ -11,6 +11,7 @@
 
 struct hsm_store_context {
        const char *basepath;
+       const char *errmsg;
 };
 
 struct hsm_store_handle {
@@ -25,23 +26,41 @@ struct hsm_store_handle {
 struct hsm_store_context *hsm_store_init(void)
 {
        struct hsm_store_context *ctx;
-       struct stat st;
 
-       ctx = malloc(sizeof(struct hsm_store_context));
+       ctx = calloc(1, sizeof(struct hsm_store_context));
        if (ctx == NULL) {
                errno = ENOMEM;
                return NULL;
        }
 
+       ctx->errmsg = "";
+
+       return ctx;
+}
+
+/*
+  return an error message for the last failed operation
+ */
+const char *hsm_store_errmsg(struct hsm_store_context *ctx)
+{
+       return ctx->errmsg;
+}
+
+/*
+  connect to the store
+ */
+int hsm_store_connect(struct hsm_store_context *ctx, const char *fsname)
+{
+       struct stat st;
+
        ctx->basepath = HSM_STORE_PATH;
-       if (stat(ctx->basepath, &st) != 0 ||
-           !S_ISDIR(st.st_mode)) {
-               errno = EINVAL;
-               free(ctx);
-               return NULL;
+
+       if (stat(ctx->basepath, &st) != 0 || !S_ISDIR(st.st_mode)) {
+               ctx->errmsg = "Invalid store path";
+               return -1;
        }
 
-       return ctx;
+       return 0;
 }
 
 /*
@@ -80,11 +99,13 @@ struct hsm_store_handle *hsm_store_open(struct hsm_store_context *ctx,
 
        fname = store_fname(ctx, device, inode);
        if (fname == NULL) {
+               ctx->errmsg = "Unable to allocate store filename";
                return NULL;
        }
 
        h = malloc(sizeof(struct hsm_store_handle));
        if (h == NULL) {
+               ctx->errmsg = "Unable to allocate store handle";
                errno = ENOMEM;
                free(fname);
                return NULL;
@@ -102,6 +123,7 @@ struct hsm_store_handle *hsm_store_open(struct hsm_store_context *ctx,
        free(fname);
 
        if (h->fd == -1) {
+               ctx->errmsg = "Unable to open store file";
                free(h);
                return NULL;
        }
@@ -139,9 +161,14 @@ size_t hsm_store_read(struct hsm_store_handle *h, uint8_t *buf, size_t n)
 /*
   write to a stored file
  */
-size_t hsm_store_write(struct hsm_store_handle *h, uint8_t *buf, size_t n)
+int hsm_store_write(struct hsm_store_handle *h, uint8_t *buf, size_t n)
 {
-       return write(h->fd, buf, n);
+       size_t nwritten = write(h->fd, buf, n);
+       if (nwritten != n) {
+               h->ctx->errmsg = "write failed";
+               return -1;
+       }
+       return 0;
 }
 
 /*