Esempio n. 1
0
int
old_readdir(glfs_t *fs)
{
    struct glfs_object *root = NULL;
    struct glfs_fd *fd = NULL;
    struct stat *sb = NULL;
    char buf[512];
    struct dirent *entry = NULL;
    int ret = -1;
    struct glfs_object *glhandle = NULL;

    if (!fs)
        return -1;

    root = glfs_h_lookupat(fs, NULL, "/", sb, 0);
    VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_h_lookupat", !!root, ret, out);

    fd = glfs_opendir(fs, "/");
    VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_opendir", !!fd, ret, out);

    while (glfs_readdir_r(fd, (struct dirent *)buf, &entry), entry) {
        if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
            glhandle = glfs_h_lookupat(fs, root, "/", sb, 0);
            VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_h_lookupat", !!glhandle,
                                                  ret, out);
        }
    }

    glfs_closedir(fd);

    ret = 0;
out:
    return ret;
}
Esempio n. 2
0
bool GlusterBackend::recursiveListDir(const char* path,vector<BackendItem>& _list) {
  glfs_fd_t *dp;
  struct dirent *dirp;
  if((dp  = glfs_opendir((glfs_t*)fs,path)) == NULL) {
      LOG(ERROR)<<"Error in opening"<<path<<" in GlusterFS.ErrorNo:"<<errno;
      return false;
  }

  bool res = true;
  while ((dirp = glfs_readdir(dp)) != NULL) {
    if(dirp->d_type == DT_REG){//File
      struct stat st;
      char newPath[2048];
      int len = 0;
      if(strcmp(path,"/")==0)//root
        len = snprintf(newPath, sizeof(newPath)-1, "%s%s", path, dirp->d_name);
      else
        len = snprintf(newPath, sizeof(newPath)-1, "%s/%s", path, dirp->d_name);
      newPath[len]= 0;
      glfs_stat((glfs_t*)fs,newPath,&st);

      char mtime[1024];
      len = snprintf(mtime,sizeof(mtime),"%lld.%.9ld", (long long)st.st_mtim.tv_sec, st.st_mtim.tv_nsec);
      mtime[len] = 0;
      _list.emplace_back(BackendItem(string(newPath),st.st_size,"",string(mtime)));
    }else if(dirp->d_type == DT_DIR){//Directory
      if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0)
          continue;
      char newPath[2048];
      int len = 0;
      if(strcmp(path,"/")==0)//root
        len = snprintf(newPath, sizeof(newPath)-1, "%s%s", path, dirp->d_name);
      else
        len = snprintf(newPath, sizeof(newPath)-1, "%s/%s", path, dirp->d_name);
      newPath[len] = 0;
      res = recursiveListDir(newPath, _list);
    }
  }
  glfs_closedir(dp);
  return res;
}
Esempio n. 3
0
int
test_dirops (glfs_t *fs)
{
	glfs_fd_t *fd = NULL;
	char buf[512];
	struct dirent *entry = NULL;

	fd = glfs_opendir (fs, "/");
	if (!fd) {
		fprintf (stderr, "/: %s\n", strerror (errno));
		return -1;
	}

	fprintf (stderr, "Entries:\n");
	while (glfs_readdir_r (fd, (struct dirent *)buf, &entry), entry) {
		fprintf (stderr, "%s: %lu\n", entry->d_name, glfs_telldir (fd));
	}

	glfs_closedir (fd);
	return 0;
}
Esempio n. 4
0
static fsal_status_t read_dirents(struct fsal_obj_handle *dir_hdl,
				  const struct req_op_context *opctx,
				  fsal_cookie_t * whence, void *dir_state,
				  fsal_readdir_cb cb, bool * eof)
{
	int rc = 0;
	fsal_status_t status = { ERR_FSAL_NO_ERROR, 0 };
	struct glfs_fd *glfd = NULL;
	long offset = 0;
	struct dirent *pde = NULL;
	struct glusterfs_export *glfs_export =
	    container_of(dir_hdl->export, struct glusterfs_export, export);
	struct glusterfs_handle *objhandle =
	    container_of(dir_hdl, struct glusterfs_handle, handle);
#ifdef GLTIMING
	struct timespec s_time, e_time;

	now(&s_time);
#endif

	glfd = glfs_h_opendir(glfs_export->gl_fs, objhandle->glhandle);
	if (glfd == NULL) {
		return gluster2fsal_error(errno);
	}

	if (whence != NULL) {
		offset = *whence;
	}

	glfs_seekdir(glfd, offset);

	while (!(*eof)) {
		struct dirent de;

		rc = glfs_readdir_r(glfd, &de, &pde);
		if (rc == 0 && pde != NULL) {
			/* skip . and .. */
			if ((strcmp(de.d_name, ".") == 0)
			    || (strcmp(de.d_name, "..") == 0)) {
				continue;
			}

			if (!cb
			    (opctx, de.d_name, dir_state, glfs_telldir(glfd))) {
				goto out;
			}
		} else if (rc == 0 && pde == NULL) {
			*eof = true;
		} else if (rc != 0) {
			status = gluster2fsal_error(errno);
			goto out;
		} else {
			/* Can't happen */
			abort();
		}
	}

 out:
	rc = glfs_closedir(glfd);
	if (rc < 0) {
		status = gluster2fsal_error(errno);
	}
#ifdef GLTIMING
	now(&e_time);
	latency_update(&s_time, &e_time, lat_read_dirents);
#endif
	return status;
}
Esempio n. 5
0
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;
                }
        }
}