static fsal_status_t renamefile(struct fsal_obj_handle *olddir_hdl, const struct req_op_context *opctx, const char *old_name, struct fsal_obj_handle *newdir_hdl, const char *new_name) { int rc = 0, credrc = 0; fsal_status_t status = { ERR_FSAL_NO_ERROR, 0 }; struct glusterfs_export *glfs_export = container_of(olddir_hdl->export, struct glusterfs_export, export); struct glusterfs_handle *srcparenthandle = container_of(olddir_hdl, struct glusterfs_handle, handle); struct glusterfs_handle *dstparenthandle = container_of(newdir_hdl, struct glusterfs_handle, handle); #ifdef GLTIMING struct timespec s_time, e_time; now(&s_time); #endif credrc = setglustercreds(glfs_export, &opctx->creds->caller_uid, &opctx->creds->caller_gid, opctx->creds->caller_glen, opctx->creds->caller_garray); if (credrc != 0) { status = gluster2fsal_error(EPERM); LogFatal(COMPONENT_FSAL, "Could not set Ganesha credentials"); goto out; } rc = glfs_h_rename(glfs_export->gl_fs, srcparenthandle->glhandle, old_name, dstparenthandle->glhandle, new_name); credrc = setglustercreds(glfs_export, NULL, NULL, 0, NULL); if (credrc != 0) { status = gluster2fsal_error(EPERM); LogFatal(COMPONENT_FSAL, "Could not set Ganesha credentials"); goto out; } if (rc != 0) { status = gluster2fsal_error(errno); goto out; } out: #ifdef GLTIMING now(&e_time); latency_update(&s_time, &e_time, lat_renamefile); #endif return status; }
int main (int argc, char *argv[]) { glfs_t *fs = NULL; int ret = 0, i; glfs_fd_t *fd = NULL; char *filename = "/a1"; char *filename2 = "/a2"; struct stat sb = {0, }; struct callback_arg cbk; char *logfile = NULL; char *volname = NULL; int cnt = 1; struct callback_inode_arg *in_arg = NULL; struct glfs_object *root = NULL, *leaf = NULL; cbk.reason = 0; fprintf (stderr, "Starting libgfapi_fini\n"); if (argc != 3) { fprintf (stderr, "Invalid argument\n"); exit(1); } volname = argv[1]; logfile = argv[2]; fs = glfs_new (volname); if (!fs) { fprintf (stderr, "glfs_new: returned NULL\n"); return 1; } ret = glfs_set_volfile_server (fs, "tcp", "localhost", 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); sleep (2); root = glfs_h_lookupat (fs, NULL, "/", &sb, 0); if (!root) { ret = -1; LOG_ERR ("glfs_h_lookupat root", ret); } leaf = glfs_h_lookupat (fs, root, filename, &sb, 0); if (!leaf) { ret = -1; LOG_IF_NO_ERR ("glfs_h_lookupat leaf", ret); } leaf = glfs_h_creat (fs, root, filename, O_RDWR, 0644, &sb); if (!leaf) { ret = -1; LOG_ERR ("glfs_h_lookupat leaf", ret); } fprintf (stderr, "glfs_h_create leaf - %p\n", leaf); leaf = glfs_h_lookupat (fs, root, filename2, &sb, 0); if (!leaf) { ret = -1; LOG_IF_NO_ERR ("glfs_h_lookupat leaf", ret); } ret = glfs_h_rename (fs, root, filename, root, filename2); LOG_ERR("glfs_rename", ret); while (cnt++ < 5) { ret = glfs_h_poll_upcall(fs, &cbk); LOG_ERR ("glfs_h_poll_upcall", ret); /* There should not be any upcalls sent */ if (cbk.reason != GFAPI_CBK_EVENT_NULL) { fprintf (stderr, "Error: Upcall received(%d)\n", cbk.reason); exit (1); } } ret = glfs_fini(fs); LOG_ERR("glfs_fini", ret); fprintf (stderr, "End of libgfapi_fini\n"); exit(0); }