示例#1
0
jdm_fshandle_t *
jdm_getfshandle( char *mntpnt )
{
	fshandle_t *fshandlep;
	size_t fshandlesz;
	char resolved[MAXPATHLEN];

	/* sanity checks */
	ASSERT( sizeof( fshandle_t ) == FSHANDLE_SZ );
	ASSERT( sizeof( filehandle_t ) == FILEHANDLE_SZ );
	ASSERT( sizeof( filehandle_t )
		-
		offsetofmember( filehandle_t, fh_pad )
		==
		FILEHANDLE_SZ_FOLLOWING );
	ASSERT( sizeofmember( filehandle_t, fh_pad ) == FILEHANDLE_SZ_PAD );
	ASSERT( FILEHANDLE_SZ_PAD == sizeof( int16_t ));

	fshandlep = NULL; /* for lint */
	fshandlesz = sizeof( *fshandlep );

	if (!realpath( mntpnt, resolved ))
		return NULL;

	if (path_to_fshandle( resolved, ( void ** )&fshandlep, &fshandlesz ))
		return NULL;

	assert( fshandlesz == sizeof( *fshandlep ));

	return ( jdm_fshandle_t * )fshandlep;
}
示例#2
0
int vfs_get_root_handle(struct vfs_filesystem *vfs_fs,
			struct vfs_fsal_export *exp)
{
	enum fsid_type fsid_type;
	struct fsal_fsid__ fsid;
	int fd;
	int retval;
	void *data;
	size_t sz;
	vfs_file_handle_t *fh;

	vfs_alloc_handle(fh);

	if (path_to_fshandle(vfs_fs->fs->path, &data, &sz) < 0) {
		retval = errno;
		LogMajor(COMPONENT_FSAL,
			 "Export root %s could not be established for XFS error %s",
			 vfs_fs->fs->path, strerror(retval));
		return retval;
	}

	fd = open(vfs_fs->fs->path, O_RDONLY | O_DIRECTORY);

	if (fd < 0) {
		retval = errno;
		LogMajor(COMPONENT_FSAL,
			 "Could not open XFS mount point %s: rc = %s (%d)",
			 vfs_fs->fs->path, strerror(retval), retval);
		return retval;
	}

	retval = vfs_fd_to_handle(fd, vfs_fs->fs, fh);

	if (retval != 0) {
		retval = errno;
		LogMajor(COMPONENT_FSAL,
			 "Get root handle for %s failed with %s (%d)",
			 vfs_fs->fs->path, strerror(retval), retval);
		goto errout;
	}

	(void) vfs_extract_fsid(fh, &fsid_type, &fsid);

	retval = re_index_fs_fsid(vfs_fs->fs, fsid_type,
				  fsid.major, fsid.minor);

	if (retval < 0) {
		LogCrit(COMPONENT_FSAL,
			"Could not re-index XFS file system fsid for %s",
			vfs_fs->fs->path);
		retval = -retval;
	}

errout:

	close(fd);

	return retval;
}
示例#3
0
struct vfs_exp_handle_ops *
get_handle_ops(char *mntdir)
{
        void *data;
        size_t sz;

        /* This is a secret handshake which libhandle requires to
         * make sure open_by_handle will work */
        if(path_to_fshandle(mntdir, &data, &sz) < 0)
                return NULL;
        free_handle(data, sz);

        return &xfs_ops;
}
示例#4
0
文件: hsmapi.c 项目: crossmeta/sgi
extern hsm_fs_ctxt_t *
HsmInitFsysContext(
const	char		*mountpoint,
	int		dumpversion)
{
	dmf_fs_ctxt_t	*dmf_fs_ctxtp;
	void		*fshanp;
	size_t		fshlen;
	dm_fsid_t	fsid;
	int		error;

	if (dumpversion != HSM_API_VERSION_1) {
		return NULL;		/* we can't handle this version */
	}

	/* Get the filesystem's DMAPI fsid for later use in building file
	   handles in HsmInitFileContext.  We use path_to_handle() because
	   dm_path_to_handle() doesn't work if the filesystem isn't mounted
	   with -o dmi.
	*/

	if (path_to_fshandle((char *)mountpoint, &fshanp, &fshlen)) {
		return NULL;
	}
	error = dm_handle_to_fsid(fshanp, fshlen, &fsid);
	free_handle(fshanp, fshlen);
	if (error) {
		return NULL;
	}

	/* Malloc space for a filesystem context, and initialize any fields
	   needed later by other routines.
	*/

	if ((dmf_fs_ctxtp = malloc(sizeof(dmf_fs_ctxt_t))) == NULL) {
		return NULL;
	}
	dmf_fs_ctxtp->dumpversion = dumpversion;
	dmf_fs_ctxtp->fsid = fsid;

	return (hsm_fs_ctxt_t *)dmf_fs_ctxtp;
}
示例#5
0
/**
 * build the export entry
 */
fsal_status_t XFSFSAL_BuildExportContext(xfsfsal_export_context_t * p_export_context,   /* OUT */
                                         fsal_path_t * p_export_path,   /* IN */
                                         char *fs_specific_options      /* IN */
    )
{
  /* Get the mount point for this lustre FS,
   * so it can be used for building .lustre/fid paths.
   */

  FILE *fp;
  struct mntent *p_mnt;
  struct stat pathstat;

  char rpath[MAXPATHLEN];
  char mntdir[MAXPATHLEN];
  char fs_spec[MAXPATHLEN];

  char *first_xfs_dir = NULL;
  char type[256];

  size_t pathlen, outlen;
  int rc;

  char *handle;
  size_t handle_len = 0;

  /* sanity check */
  if(p_export_context == NULL)
    {
      LogCrit(COMPONENT_FSAL, "NULL mandatory argument passed to %s()", __FUNCTION__);
      Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_BuildExportContext);
    }

  outlen = 0;

  if(p_export_path != NULL)
    strncpy(rpath, p_export_path->path, MAXPATHLEN);

  /* open mnt file */
  fp = setmntent(MOUNTED, "r");

  if(fp == NULL)
    {
      rc = errno;
      LogCrit(COMPONENT_FSAL, "Error %d in setmntent(%s): %s", rc, MOUNTED,
                      strerror(rc));
      Return(posix2fsal_error(rc), rc, INDEX_FSAL_BuildExportContext);
    }

  while((p_mnt = getmntent(fp)) != NULL)
    {
      /* get the longer path xfs related export that matches export path */

      if(p_mnt->mnt_dir != NULL)
        {

          pathlen = strlen(p_mnt->mnt_dir);

          if(strncmp(p_mnt->mnt_type, "xfs", 256))
            continue;

          if(first_xfs_dir == NULL)
            first_xfs_dir = p_mnt->mnt_dir;

          if((pathlen > outlen) && !strcmp(p_mnt->mnt_dir, "/"))
            {
              LogDebug(COMPONENT_FSAL,
                              "Root mountpoint is allowed for matching %s, type=%s, fs=%s",
                              rpath, p_mnt->mnt_type, p_mnt->mnt_fsname);
              outlen = pathlen;
              strncpy(mntdir, p_mnt->mnt_dir, MAXPATHLEN);
              strncpy(type, p_mnt->mnt_type, 256);
              strncpy(fs_spec, p_mnt->mnt_fsname, MAXPATHLEN);
            }
          /* in other cases, the filesystem must be <mountpoint>/<smthg> or <mountpoint>\0 */
          else if((pathlen > outlen) &&
                  !strncmp(rpath, p_mnt->mnt_dir, pathlen) &&
                  ((rpath[pathlen] == '/') || (rpath[pathlen] == '\0')))
            {
              LogFullDebug(COMPONENT_FSAL, "%s is under mountpoint %s, type=%s, fs=%s",
                              rpath, p_mnt->mnt_dir, p_mnt->mnt_type, p_mnt->mnt_fsname);

              outlen = pathlen;
              strncpy(mntdir, p_mnt->mnt_dir, MAXPATHLEN);
              strncpy(type, p_mnt->mnt_type, 256);
              strncpy(fs_spec, p_mnt->mnt_fsname, MAXPATHLEN);
            }
        }
    }

  if(outlen <= 0)
    {
      if(p_export_path == NULL)
        strncpy(mntdir, first_xfs_dir, MAXPATHLEN);
      else
        {
          LogCrit(COMPONENT_FSAL, "No mount entry matches '%s' in %s", rpath, MOUNTED);
          endmntent(fp);
          Return(ERR_FSAL_NOENT, 0, INDEX_FSAL_BuildExportContext);
        }
    }

  /* Do the path_to_fshandle call to init the xfs's libhandle */
  strncpy(p_export_context->mount_point, mntdir, MAXPATHLEN);

  if((rc = path_to_fshandle(mntdir, (void **)(&handle), &handle_len)) < 0)
    Return(ERR_FSAL_FAULT, errno, INDEX_FSAL_BuildExportContext);

  memcpy(p_export_context->mnt_fshandle_val, handle, handle_len);
  p_export_context->mnt_fshandle_len = handle_len;

  if((rc = path_to_handle(mntdir, (void **)(&handle), &handle_len)) < 0)
    Return(ERR_FSAL_FAULT, errno, INDEX_FSAL_BuildExportContext);

  memcpy(p_export_context->mnt_handle_val, handle, handle_len);
  p_export_context->mnt_handle_len = handle_len;

  p_export_context->dev_id = 1;  /** @todo BUGAZOMEU : put something smarter here, using setmntent */

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_BuildExportContext);
}
示例#6
0
static int
parent_list(int fullpath)
{
	void *handlep;
	size_t handlen;
	int error, i;
	int retval = 1;
	__u32 count;
	parent_t *entryp;
	parent_t *parentbuf = NULL;
	char *path = file->name;
	int pb_size = PARENTBUF_SZ;

	/* XXXX for linux libhandle version - to set libhandle fsfd cache */
	{
		void *fshandle;
		size_t fshlen;

		if (path_to_fshandle(mntpt, &fshandle, &fshlen) != 0) {
			fprintf(stderr, _("%s: failed path_to_fshandle \"%s\": %s\n"),
				progname, path, strerror(errno));
			goto error;
		}
	}

	if (path_to_handle(path, &handlep, &handlen) != 0) {
		fprintf(stderr, _("%s: path_to_handle failed for \"%s\"\n"), progname, path);
		goto error;
	}

	do {
		parentbuf = (parent_t *)realloc(parentbuf, pb_size);
		if (!parentbuf) {
			fprintf(stderr, _("%s: unable to allocate parent buffer: %s\n"),
				progname, strerror(errno));
			return 1;
		}

		if (fullpath) {
			error = parentpaths_by_handle(handlep,
						       handlen,
						       parentbuf,
						       pb_size,
						       &count);
		} else {
			error = parents_by_handle(handlep,
						   handlen,
						   parentbuf,
						   pb_size,
						   &count);
		}
		if (error == ERANGE) {
			pb_size *= 2;
		} else if (error) {
			fprintf(stderr, _("%s: %s call failed for \"%s\": %s\n"),
				progname, fullpath ? "parentpaths" : "parents",
				path, strerror(errno));
			goto error;
		}
	} while (error == ERANGE);

	if (count == 0) {
		/* no links for inode - something wrong here */
		fprintf(stderr, _("%s: inode-path is missing\n"), progname);
		goto error;
	}

	entryp = parentbuf;
	for (i = 0; i < count; i++) {
		print_parent_entry(entryp, fullpath);
		entryp = (parent_t*) (((char*)entryp) + entryp->p_reclen);
	}

	retval = 0;
error:
	free(parentbuf);
	return retval;
}