/* * Create a parent directory using the gfapi. */ static inline bool gfapi_makedir(glfs_t *glfs, const char *directory) { char *bp; struct stat st; bool retval = false; POOL_MEM new_directory(PM_FNAME); pm_strcpy(new_directory, directory); /* * See if the parent exists. */ bp = strrchr(new_directory.c_str(), '/'); if (bp) { /* * See if we reached the root. */ if (bp == new_directory.c_str()) { /* * Create the directory. */ if (glfs_mkdir(glfs, directory, 0750) == 0) { retval = true; } } else { *bp = '\0'; if (glfs_stat(glfs, new_directory.c_str(), &st) != 0) { switch (errno) { case ENOENT: /* * Make sure our parent exists. */ retval = gfapi_makedir(glfs, new_directory.c_str()); if (!retval) { return false; } /* * Create the directory. */ if (glfs_mkdir(glfs, directory, 0750) == 0) { retval = true; } break; default: break; } } else { retval = true; } } } return retval; }
bool glfs_java_file_mkdir (glfs_t *glfs, const char *path) { int ret; ret = glfs_mkdir (glfs, path, S_IFREG | 0755); return (ret == 0); }
bool GlusterBackend::createDirectory(const char* path){ if(glfs_mkdir((glfs_t*)fs, path,0775)!=0){ if(errno == EEXIST)//already exist return true; LOG(ERROR)<<"Error in creating directory:"<<path<<" erroNo:"<<errno; return false; } return true; }
static int mkdir_with_fs (glfs_t *fs) { int ret; mode_t mode = get_default_dir_mode_perm (); if (state->parents) { ret = gluster_create_path (fs, state->gluster_url->path, mode); } else { ret = glfs_mkdir (fs, state->gluster_url->path, mode); } if (ret == -1) { error (0, errno, "cannot create directory `%s'", state->url); goto out; } out: return ret; }
int test_chdir (glfs_t *fs) { int ret = -1; ino_t ino = 0; struct stat st; char *topdir = "/topdir"; char *linkdir = "/linkdir"; char *subdir = "./subdir"; char *respath = NULL; char pathbuf[4096]; ret = glfs_mkdir (fs, topdir, 0755); if (ret) { fprintf (stderr, "mkdir(%s): %s\n", topdir, strerror (errno)); return -1; } respath = glfs_getcwd (fs, pathbuf, 4096); fprintf (stdout, "getcwd() = %s\n", respath); ret = glfs_symlink (fs, topdir, linkdir); if (ret) { fprintf (stderr, "symlink(%s, %s): %s\n", topdir, linkdir, strerror (errno)); return -1; } ret = glfs_chdir (fs, linkdir); if (ret) { fprintf (stderr, "chdir(%s): %s\n", linkdir, strerror (errno)); return -1; } respath = glfs_getcwd (fs, pathbuf, 4096); fprintf (stdout, "getcwd() = %s\n", respath); respath = glfs_realpath (fs, subdir, pathbuf); if (respath) { fprintf (stderr, "realpath(%s) worked unexpectedly: %s\n", subdir, respath); return -1; } ret = glfs_mkdir (fs, subdir, 0755); if (ret) { fprintf (stderr, "mkdir(%s): %s\n", subdir, strerror (errno)); return -1; } respath = glfs_realpath (fs, subdir, pathbuf); if (!respath) { fprintf (stderr, "realpath(%s): %s\n", subdir, strerror (errno)); } else { fprintf (stdout, "realpath(%s) = %s\n", subdir, respath); } ret = glfs_chdir (fs, subdir); if (ret) { fprintf (stderr, "chdir(%s): %s\n", subdir, strerror (errno)); return -1; } respath = glfs_getcwd (fs, pathbuf, 4096); fprintf (stdout, "getcwd() = %s\n", respath); respath = glfs_realpath (fs, "/linkdir/subdir", pathbuf); if (!respath) { fprintf (stderr, "realpath(/linkdir/subdir): %s\n", strerror (errno)); } else { fprintf (stdout, "realpath(/linkdir/subdir) = %s\n", respath); } return 0; }
int main (int argc, char *argv[]) { glfs_t *fs = NULL; glfs_t *fs2 = NULL; int ret = 0; glfs_fd_t *fd = NULL; glfs_fd_t *fd2 = NULL; struct stat sb = {0, }; char readbuf[32]; char writebuf[32]; char *filename = "/filename2"; fs = glfs_new ("fsync"); if (!fs) { fprintf (stderr, "glfs_new: returned NULL\n"); return 1; } // ret = glfs_set_volfile (fs, "/tmp/posix.vol"); ret = glfs_set_volfile_server (fs, "tcp", "localhost", 24007); // ret = glfs_set_volfile_server (fs, "unix", "/tmp/gluster.sock", 0); ret = glfs_set_logging (fs, "/dev/stderr", 7); ret = glfs_init (fs); fprintf (stderr, "glfs_init: returned %d\n", ret); sleep (2); fs2 = glfs_new ("fsync"); if (!fs2) { fprintf (stderr, "glfs_new: returned NULL\n"); return 1; } // ret = glfs_set_volfile (fs2, "/tmp/posix.vol"); ret = glfs_set_volfile_server (fs2, "tcp", "localhost", 24007); ret = glfs_set_logging (fs2, "/dev/stderr", 7); ret = glfs_init (fs2); fprintf (stderr, "glfs_init: returned %d\n", ret); ret = glfs_lstat (fs, filename, &sb); fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); fd = glfs_creat (fs, filename, O_RDWR, 0644); fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno)); fd2 = glfs_open (fs2, filename, O_RDWR); fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno)); sprintf (writebuf, "hi there\n"); ret = glfs_write (fd, writebuf, 32, 0); glfs_lseek (fd2, 0, SEEK_SET); ret = glfs_read (fd2, readbuf, 32, 0); printf ("read %d, %s", ret, readbuf); glfs_close (fd); glfs_close (fd2); filename = "/filename3"; ret = glfs_mknod (fs, filename, S_IFIFO, 0); fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); ret = glfs_lstat (fs, filename, &sb); fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); ret = glfs_rename (fs, filename, "/filename4"); fprintf (stderr, "rename(%s): (%d) %s\n", filename, ret, strerror (errno)); ret = glfs_unlink (fs, "/filename4"); fprintf (stderr, "unlink(%s): (%d) %s\n", "/filename4", ret, strerror (errno)); filename = "/dirname2"; ret = glfs_mkdir (fs, filename, 0); fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); ret = glfs_lstat (fs, filename, &sb); fprintf (stderr, "lstat(%s): (%d) %s\n", filename, ret, strerror (errno)); ret = glfs_rmdir (fs, filename); fprintf (stderr, "rmdir(%s): (%d) %s\n", filename, ret, strerror (errno)); test_dirops (fs); test_xattr (fs); test_chdir (fs); // done glfs_fini (fs); glfs_fini (fs2); return ret; }
static int large_number_of_fops (glfs_t *fs) { int ret = 0; int i = 0; glfs_fd_t *fd = NULL; glfs_fd_t *fd1 = NULL; char *dir1 = NULL, *dir2 = NULL, *filename1 = NULL, *filename2 = NULL; char *buf = NULL; struct stat sb = {0, }; for (i = 0 ; i < FOP_LOOP_COUNT ; i++) { ret = asprintf (&dir1, "dir%d", extension); if (ret < 0) { fprintf (stderr, "cannot construct filename (%s)", strerror (errno)); return ret; } extension++; ret = glfs_mkdir (fs, dir1, 0755); if (ret < 0) { fprintf (stderr, "mkdir(%s): %s\n", dir1, strerror (errno)); return -1; } fd = glfs_opendir (fs, dir1); if (!fd) { fprintf (stderr, "/: %s\n", strerror (errno)); return -1; } ret = glfs_fsetxattr (fd, "user.dirfattr", "fsetxattr", 8, 0); if (ret < 0) { fprintf (stderr, "fsetxattr(%s): %d (%s)\n", dir1, ret, strerror (errno)); return -1; } ret = glfs_closedir (fd); if (ret < 0) { fprintf (stderr, "glfs_closedir failed with ret: %d (%s)\n", ret, strerror (errno)); return -1; } ret = glfs_rmdir (fs, dir1); if (ret < 0) { fprintf (stderr, "glfs_unlink failed with ret: %d (%s)\n", ret, strerror (errno)); return -1; } ret = asprintf (&filename1, "file%d", extension); if (ret < 0) { fprintf (stderr, "cannot construct filename (%s)", strerror (errno)); return ret; } ret = asprintf (&filename2, "file-%d", extension); if (ret < 0) { fprintf (stderr, "cannot construct filename (%s)", strerror (errno)); return ret; } extension++; fd = glfs_creat (fs, filename1, O_RDWR, 0644); if (!fd) { fprintf (stderr, "%s: (%p) %s\n", filename1, fd, strerror (errno)); return -1; } ret = glfs_rename (fs, filename1, filename2); if (ret < 0) { fprintf (stderr, "glfs_rename failed with ret: %d (%s)\n", ret, strerror (errno)); return -1; } ret = glfs_lstat (fs, filename2, &sb); if (ret < 0) { fprintf (stderr, "glfs_lstat failed with ret: %d (%s)\n", ret, strerror (errno)); return -1; } ret = glfs_close (fd); if (ret < 0) { fprintf (stderr, "glfs_close failed with ret: %d (%s)\n", ret, strerror (errno)); return -1; } ret = glfs_unlink (fs, filename2); if (ret < 0) { fprintf (stderr, "glfs_unlink failed with ret: %d (%s)\n", ret, strerror (errno)); return -1; } } }