void gluster_cleanup_vars(struct glfs_object *glhandle) { if (glhandle) { /* Error ignored, this is a cleanup operation, can't do much. */ /** @todo: Useful point for logging? */ glfs_h_close(glhandle); } }
/** * @brief Release a DS object * * @param[in] obj_pub The object to release * * @return NFS Status codes. */ static void release(struct fsal_ds_handle *const ds_pub) { int rc = 0; struct glfs_ds_handle *ds = container_of(ds_pub, struct glfs_ds_handle, ds); fsal_ds_handle_fini(&ds->ds); if (ds->glhandle) { rc = glfs_h_close(ds->glhandle); if (rc) { LogMajor(COMPONENT_PNFS, "glfs_h_close returned error %s(%d)", strerror(errno), errno); } } gsh_free(ds); }
static fsal_status_t handle_release(struct fsal_obj_handle *obj_hdl) { int rc = 0; fsal_status_t status = { ERR_FSAL_NO_ERROR, 0 }; struct glusterfs_handle *objhandle = container_of(obj_hdl, struct glusterfs_handle, handle); #ifdef GLTIMING struct timespec s_time, e_time; now(&s_time); #endif rc = fsal_obj_handle_uninit(&objhandle->handle); if (rc != 0) { status = gluster2fsal_error(rc); goto out; } if (objhandle->glfd) { rc = glfs_close(objhandle->glfd); if (rc) { status = gluster2fsal_error(errno); /* cleanup as much as possible */ } } if (objhandle->glhandle) { rc = glfs_h_close(objhandle->glhandle); if (rc) { status = gluster2fsal_error(errno); goto out; } } gsh_free(objhandle); out: #ifdef GLTIMING now(&e_time); latency_update(&s_time, &e_time, lat_handle_release); #endif return status; }
int main(int argc, char *argv[]) { int ret = -1; int flags = O_RDWR | O_SYNC; glfs_t *fs = NULL; glfs_fd_t *fd = NULL; char *volname = NULL; char *logfile = NULL; const char *filename = "file_tmp"; struct glfs_object *object = NULL; acl_t acl = NULL; struct stat sb; if (argc != 3) { fprintf(stderr, "Invalid argument\n"); return 1; } volname = argv[1]; logfile = argv[2]; fs = glfs_new(volname); if (!fs) VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_new", ret, out); ret = glfs_set_volfile_server(fs, "tcp", "localhost", 24007); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_volfile_server", ret, out); ret = glfs_set_logging(fs, logfile, 7); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_logging", ret, out); ret = glfs_init(fs); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_init", ret, out); fd = glfs_creat(fs, filename, flags, 0044); if (fd == NULL) { ret = -1; VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_creat", ret, out); } glfs_close(fd); object = glfs_h_lookupat(fs, NULL, filename, NULL, 0); if (object == NULL) { ret = -1; VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_lookupat", ret, out); } ret = glfs_chown(fs, filename, 99, 99); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_chown", ret, out); ret = glfs_setfsuid(99); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_setfsuid", ret, out); ret = glfs_setfsgid(99); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_setfsgid", ret, out); acl = glfs_h_acl_get(fs, object, ACL_TYPE_ACCESS); if (acl == NULL) { ret = -1; VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_acl_get", ret, out); } ret = glfs_h_acl_set(fs, object, ACL_TYPE_ACCESS, acl); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_acl_get", ret, out); out: glfs_setfsuid(0); glfs_setfsgid(0); if (object) glfs_h_close(object); if (fs) glfs_fini(fs); return ret; }
struct glfs_object * glfs_h_mknod (struct glfs *fs, struct glfs_object *parent, const char *path, mode_t mode, dev_t dev, struct stat *stat) { int ret = -1; xlator_t *subvol = NULL; inode_t *inode = NULL; loc_t loc = {0, }; struct iatt iatt = {0, }; uuid_t gfid; dict_t *xattr_req = NULL; struct glfs_object *object = NULL; /* validate in args */ if ((fs == NULL) || (parent == NULL) || (path == NULL)) { errno = EINVAL; return NULL; } __glfs_entry_fs (fs); /* get the active volume */ subvol = glfs_active_subvol (fs); if (!subvol) { ret = -1; errno = EIO; goto out; } /* get/refresh the in arg objects inode in correlation to the xlator */ inode = glfs_resolve_inode (fs, subvol, parent); if (!inode) { errno = ESTALE; goto out; } xattr_req = dict_new (); if (!xattr_req) { ret = -1; errno = ENOMEM; goto out; } uuid_generate (gfid); ret = dict_set_static_bin (xattr_req, "gfid-req", gfid, 16); if (ret) { ret = -1; errno = ENOMEM; goto out; } GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, path); /* fop/op */ ret = syncop_mknod (subvol, &loc, mode, dev, xattr_req, &iatt); DECODE_SYNCOP_ERR (ret); /* populate out args */ if (ret == 0) { ret = glfs_loc_link (&loc, &iatt); if (ret != 0) { goto out; } if (stat) glfs_iatt_to_stat (fs, &iatt, stat); ret = glfs_create_object (&loc, &object); } out: if (ret && object != NULL) { glfs_h_close (object); object = NULL; } loc_wipe(&loc); if (inode) inode_unref (inode); if (xattr_req) dict_unref (xattr_req); glfs_subvol_done (fs, subvol); return object; }
struct glfs_object * glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path, int flags, mode_t mode, struct stat *stat) { int ret = -1; struct glfs_fd *glfd = NULL; xlator_t *subvol = NULL; inode_t *inode = NULL; loc_t loc = {0, }; struct iatt iatt = {0, }; uuid_t gfid; dict_t *xattr_req = NULL; struct glfs_object *object = NULL; /* validate in args */ if ((fs == NULL) || (parent == NULL) || (path == NULL)) { errno = EINVAL; return NULL; } __glfs_entry_fs (fs); /* get the active volume */ subvol = glfs_active_subvol (fs); if (!subvol) { ret = -1; errno = EIO; goto out; } /* get/refresh the in arg objects inode in correlation to the xlator */ inode = glfs_resolve_inode (fs, subvol, parent); if (!inode) { errno = ESTALE; goto out; } xattr_req = dict_new (); if (!xattr_req) { ret = -1; errno = ENOMEM; goto out; } uuid_generate (gfid); ret = dict_set_static_bin (xattr_req, "gfid-req", gfid, 16); if (ret) { ret = -1; errno = ENOMEM; goto out; } GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, path); glfd = glfs_fd_new (fs); if (!glfd) goto out; glfd->fd = fd_create (loc.inode, getpid()); if (!glfd->fd) { ret = -1; errno = ENOMEM; goto out; } /* fop/op */ ret = syncop_create (subvol, &loc, flags, mode, glfd->fd, xattr_req, &iatt); DECODE_SYNCOP_ERR (ret); /* populate out args */ if (ret == 0) { /* TODO: If the inode existed in the cache (say file already exists), then the glfs_loc_link will not update the loc.inode, as a result we will have a 0000 GFID that we would copy out to the object, this needs to be fixed. */ ret = glfs_loc_link (&loc, &iatt); if (ret != 0) { goto out; } if (stat) glfs_iatt_to_stat (fs, &iatt, stat); ret = glfs_create_object (&loc, &object); } out: if (ret && object != NULL) { glfs_h_close (object); object = NULL; } loc_wipe(&loc); if (inode) inode_unref (inode); if (xattr_req) dict_unref (xattr_req); if (glfd) { glfs_fd_destroy (glfd); glfd = NULL; } glfs_subvol_done (fs, subvol); return object; }
int main (int argc, char *argv[]) { int ret = 0; glfs_t *fs = NULL; struct glfs_object *root = NULL, *file_obj = NULL; struct stat sb = {0, }; char readbuf[32], writebuf[32]; char *filename = "file.txt"; char *logfile = NULL; char *volname = NULL; char *hostname = NULL; if (argc != 4) { fprintf (stderr, "Invalid argument\n"); exit(1); } hostname = argv[1]; volname = argv[2]; logfile = argv[3]; fs = glfs_new (volname); if (!fs) { fprintf (stderr, "glfs_new: returned NULL\n"); ret = -1; } ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007); LOG_ERR("glfs_set_volfile_server", ret); ret = glfs_set_logging (fs, logfile, 7); LOG_ERR("glfs_set_logging", ret); ret = glfs_init (fs); LOG_ERR("glfs_init", ret); root = glfs_h_lookupat (fs, NULL, "/", &sb, 0); if (root == NULL) { fprintf (stderr, "glfs_h_lookupat: error on lookup of / ,%s\n", strerror (errno)); goto out; } file_obj = glfs_h_creat (fs, root, filename, O_CREAT, 0644, &sb); if (file_obj == NULL) { fprintf (stderr, "glfs_h_creat: error on create of %s: from (%p),%s\n", filename, root, strerror (errno)); goto out; } /* test read/write based on anonymous fd */ memcpy (writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32); ret = glfs_h_anonymous_write (fs, file_obj, writebuf, 32, 0); if (ret < 0) LOG_ERR ("glfs_h_anonymous_write", ret); ret = glfs_h_anonymous_read (fs, file_obj, readbuf, 32, 0); if (ret < 0) LOG_ERR ("glfs_h_anonymous_read", ret); if (memcmp (readbuf, writebuf, 32)) { fprintf (stderr, "Failed to read what I wrote: %s %s\n", readbuf, writebuf); ret = -1; goto out; } ret = 0; out: if (file_obj) glfs_h_close (file_obj); if (fs) { ret = glfs_fini(fs); fprintf (stderr, "glfs_fini(fs) returned %d \n", ret); } if (ret) exit(1); exit(0); }