Exemplo n.º 1
0
fsal_status_t fsal_internal_handle2fd(xfsfsal_op_context_t * p_context,
                                      xfsfsal_handle_t * phandle, int *pfd, int oflags)
{
  int rc = 0;
  int errsv = 0;

  if(!phandle || !pfd || !p_context)
    ReturnCode(ERR_FSAL_FAULT, 0);

  rc = open_by_handle(phandle->data.handle_val, phandle->data.handle_len, oflags);
  if(rc == -1)
    {
      errsv = errno;

      if(errsv == EISDIR)
        {
          if((rc =
              open_by_handle(phandle->data.handle_val, phandle->data.handle_len, O_DIRECTORY) < 0))
            ReturnCode(posix2fsal_error(errsv), errsv);
        }
      else
        ReturnCode(posix2fsal_error(errsv), errsv);
    }

  *pfd = rc;

  ReturnCode(ERR_FSAL_NO_ERROR, 0);
}                               /* fsal_internal_handle2fd */
Exemplo n.º 2
0
int vfs_open_by_handle(struct vfs_filesystem *fs,
		       vfs_file_handle_t *fh, int openflags,
		       fsal_errors_t *fsal_error)
{
	int fd;

	LogXFSHandle(fh);

	if (openflags == (O_PATH | O_NOACCESS))
		openflags = O_DIRECTORY;

	fd = open_by_handle(fh->handle_data, fh->handle_len, openflags);
	if (fd < 0) {
		fd = -errno;
		if (fd == -ENOENT)
			*fsal_error = posix2fsal_error(ESTALE);
		else
			*fsal_error = posix2fsal_error(-fd);
	}
	return fd;
}
Exemplo n.º 3
0
static int
vfs_xfs_open_by_handle(struct fsal_export *exp,
                       vfs_file_handle_t *fh,
                       int openflags,
                       fsal_errors_t *fsal_error)
{
        int fd;

        if(openflags == (O_PATH|O_NOACCESS))
                openflags = O_DIRECTORY;

        fd = open_by_handle(fh->handle, fh->handle_bytes, openflags);
        if(fd < 0) {
                fd = -errno;
                if(fd == -ENOENT)
                        *fsal_error = ERR_FSAL_STALE;
                else
                        *fsal_error = p2fsal_error(-fd);
        }
        return fd;
}
Exemplo n.º 4
0
extern int
HsmInitFileContext(
	hsm_f_ctxt_t	*contextp,
const	xfs_bstat_t	*statp)
{
	dmf_f_ctxt_t	*dmf_f_ctxtp = (dmf_f_ctxt_t *)contextp;
	XFSattrvalue1_t	*dmfattrp;
	int		attrlen;
	void		*hanp;
	size_t		hlen;
	dm_ino_t	ino;
	dm_igen_t	igen;
	int		fd;
	int		error;

	dmf_f_ctxtp->candidate = 0; /* assume file will NOT be of interest */

	/* Try and rule out a dualstate inode by doing some quick tests. */

	if ((statp->bs_mode & S_IFMT) != S_IFREG) {
		return 0;	/* not a regular file */
	}
	if ((statp->bs_xflags & XFS_XFLAG_HASATTR) == 0) {
		return 0;	/* no DMF attribute exists */
	}
	if ((statp->bs_dmevmask & DUALSTATE_BITS) != DUALSTATE_BITS) {
		return 0;	/* non-dualstate managed region bits */
	}

	/* We have a likely candidate, so we have to pay the price and look
	   for the DMF attribute.  (It could be in a disk block separate from
	   the inode.)
	*/

	ino = (dm_ino_t)statp->bs_ino;
	igen = (dm_igen_t)statp->bs_gen;
	if (dm_make_handle(&dmf_f_ctxtp->fsys.fsid, &ino, &igen, &hanp, &hlen) != 0) {
		return 0;	/* can't make a proper handle */
	}

	/* The following code should eventually be replaced with the
	   attr_multif-by-handle call when it is available.
	*/

	fd = open_by_handle(hanp, hlen, O_RDONLY);
	dm_handle_free(hanp, hlen);
	if (fd < 0) {
                return 0;
	}
	attrlen = sizeof(dmf_f_ctxtp->attrval);
	error = attr_getf(fd, DMF_ATTR_NAME, dmf_f_ctxtp->attrval,
		&attrlen, ATTR_ROOT);
	(void)close(fd);
	if (error) {
		return 0;
 	}

	if (attrlen != DMF_ATTR_LEN) {
                return 0;	/* not the right length to be the attribute */
	}

	dmfattrp = (XFSattrvalue1_t *)dmf_f_ctxtp->attrval;
	if (dmfattrp->version != XFS_ATTR_VERSION_1) {
		return 0;	/* we don't support this version */
	}
	if (dmfattrp->state[0] != '\0') {
		return 0;	/* should be zero */
	}
	if (dmfattrp->state[1] != DMF_ST_DUALSTATE &&
	    dmfattrp->state[1] != DMF_ST_UNMIGRATING) {
		return 0;
	}

	/* We have a DMF dual state file. */

	dmf_f_ctxtp->candidate = 1;
	dmf_f_ctxtp->filesize = BTOBB(statp->bs_size);
	return 0;
}