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);
+ }
}
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);
+ }
}
/*
/* 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);
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;
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
*/
/*
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
struct hsm_store_context {
const char *basepath;
+ const char *errmsg;
};
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;
}
/*
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;
free(fname);
if (h->fd == -1) {
+ ctx->errmsg = "Unable to open store file";
free(h);
return NULL;
}
/*
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;
}
/*