示例#1
0
文件: fsal_xattrs.c 项目: ic-hep/emi3
/**
 * Get the index of an xattr based on its name
 *
 *   \param p_objecthandle Handle of the object you want to get attribute for.
 *   \param xattr_name the name of the attribute to be read.
 *   \param pxattr_id found xattr_id
 *   
 *   \return ERR_FSAL_NO_ERROR if xattr_name exists, ERR_FSAL_NOENT otherwise
 */
fsal_status_t dpmfsal_GetXAttrIdByName(fsal_handle_t * p_objecthandle, // IN
                                       const fsal_name_t * xattr_name, // IN
                                       fsal_op_context_t * p_context, // IN
                                       unsigned int *pxattr_id // OUT
)
{
    unsigned int index;
    int found = FALSE;

    LogInfo(COMPONENT_FSAL, "dpmfsal_GetXAttrIdByName: start");

    /* sanity checks */
    if (!p_objecthandle || !xattr_name)
        Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);

    for (index = 0; index < XATTR_COUNT; index++) {
        if (do_match_type(xattr_list[index].flags,
                p_objecthandle->data.ntype) && !strcmp(
                xattr_list[index].xattr_name, xattr_name->name)) {
            found = TRUE;
            break;
        }
    }

    if (found) {
        *pxattr_id = index;
        Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_GetXAttrValue);
    } else
        Return(ERR_FSAL_NOENT, ENOENT, INDEX_FSAL_GetXAttrValue);
} /* FSAL_GetXAttrIdByName */
示例#2
0
fsal_status_t tank_getextattr_attrs(struct fsal_obj_handle *obj_hdl,
				    unsigned int xattr_id,
				    struct attrlist *p_attrs)
{
	int rc;

	/* sanity checks */
	if (!obj_hdl || !p_attrs)
		return fsalstat(ERR_FSAL_FAULT, 0);

	/* check that this index match the type of entry */
	if (xattr_id < XATTR_COUNT
	    && !do_match_type(xattr_list[xattr_id].flags,
			      obj_hdl->attributes.type)) {
		return fsalstat(ERR_FSAL_INVAL, 0);
	} else if (xattr_id >= XATTR_COUNT) {
		/* This is user defined xattr */
		LogFullDebug(COMPONENT_FSAL, "Getting attributes for xattr #%u",
			     xattr_id - XATTR_COUNT);
	}

	rc = file_attributes_to_xattr_attrs(&obj_hdl->attributes, p_attrs,
					    xattr_id);
	if (rc)
		return fsalstat(ERR_FSAL_INVAL, rc);
	return fsalstat(ERR_FSAL_NO_ERROR, 0);
}
示例#3
0
/**
 * Get the index of an xattr based on its name
 *
 *   \param p_objecthandle Handle of the object you want to get attribute for.
 *   \param xattr_name the name of the attribute to be read.
 *   \param pxattr_id found xattr_id
 *   
 *   \return ERR_FSAL_NO_ERROR if xattr_name exists, ERR_FSAL_NOENT otherwise
 */
fsal_status_t FSAL_GetXAttrIdByName(fsal_handle_t * p_objecthandle,     /* IN */
                                    const fsal_name_t * xattr_name,     /* IN */
                                    fsal_op_context_t * p_context,      /* IN */
                                    unsigned int *pxattr_id     /* OUT */
    )
{
  unsigned int index;
  int found = FALSE;

  /* sanity checks */
  if(!p_objecthandle || !xattr_name)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);

  for(index = 0; index < XATTR_COUNT; index++)
    {
      if(do_match_type(xattr_list[index].flags, p_objecthandle->object_type_reminder)
         && !strcmp(xattr_list[index].xattr_name, xattr_name->name))
        {
          found = TRUE;
          break;
        }
    }

  if(found)
    {
      *pxattr_id = index;
      Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_GetXAttrValue);
    }
  else
    Return(ERR_FSAL_NOENT, ENOENT, INDEX_FSAL_GetXAttrValue);
}                               /* FSAL_GetXAttrIdByName */
示例#4
0
/**
 * Get the value of an extended attribute from its name.
 *
 * \param p_objecthandle Handle of the object you want to get attribute for.
 * \param xattr_name the name of the attribute to be read.
 * \param p_context pointer to the current security context.
 * \param buffer_addr address of the buffer where the xattr value is to be stored.
 * \param buffer_size size of the buffer where the xattr value is to be stored.
 * \param p_output_size size of the data actually stored into the buffer.
 */
fsal_status_t FSAL_GetXAttrValueByName(fsal_handle_t * p_objecthandle,  /* IN */
                                       const fsal_name_t * xattr_name,  /* IN */
                                       fsal_op_context_t * p_context,   /* IN */
                                       caddr_t buffer_addr,     /* IN/OUT */
                                       size_t buffer_size,      /* IN */
                                       size_t * p_output_size   /* OUT */
    )
{
  unsigned int index;

  /* sanity checks */
  if(!p_objecthandle || !p_context || !p_output_size || !buffer_addr || !xattr_name)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);

  /* look for this name */

  for(index = 0; index < XATTR_COUNT; index++)
    {
      if(do_match_type(xattr_list[index].flags, p_objecthandle->object_type_reminder)
         && !strcmp(xattr_list[index].xattr_name, xattr_name->name))
        {

          return FSAL_GetXAttrValueById(p_objecthandle, index, p_context, buffer_addr,
                                        buffer_size, p_output_size);

        }
    }

  /* not found */
  Return(ERR_FSAL_NOENT, 0, INDEX_FSAL_GetXAttrValue);

}
示例#5
0
文件: fsal_xattrs.c 项目: ic-hep/emi3
/**
 * Get the value of an extended attribute from its index.
 *
 * \param p_objecthandle Handle of the object you want to get attribute for.
 * \param xattr_name the name of the attribute to be read.
 * \param p_context pointer to the current security context.
 * \param buffer_addr address of the buffer where the xattr value is to be stored.
 * \param buffer_size size of the buffer where the xattr value is to be stored.
 * \param p_output_size size of the data actually stored into the buffer.
 */
fsal_status_t dpmfsal_GetXAttrValueById(fsal_handle_t * p_objecthandle, // IN
                                        unsigned int xattr_id, // IN
                                        fsal_op_context_t * p_context, // IN
                                        caddr_t buffer_addr, // IN/OUT
                                        size_t buffer_size, // IN
                                        size_t * p_output_size // OUT
)
{
    int rc;

    LogInfo(COMPONENT_FSAL, "dpmfsal_GetXAttrValueById: start");

    /* sanity checks */
    if (!p_objecthandle || !p_context || !p_output_size || !buffer_addr)
        Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);

    /* check that this index match the type of entry */
    if (xattr_id >= XATTR_COUNT || !do_match_type(xattr_list[xattr_id].flags,
            p_objecthandle->data.ntype)) {
        Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_GetXAttrValue);
    }

    /* get the value */
    rc = xattr_list[xattr_id].get_func(p_objecthandle, p_context,
    		buffer_addr, buffer_size, p_output_size);

    Return(rc, 0, INDEX_FSAL_GetXAttrValue);

}
示例#6
0
/**
 * Get the value of an extended attribute from its index.
 *
 * \param p_objecthandle Handle of the object you want to get attribute for.
 * \param xattr_name the name of the attribute to be read.
 * \param p_context pointer to the current security context.
 * \param buffer_addr address of the buffer where the xattr value is to be stored.
 * \param buffer_size size of the buffer where the xattr value is to be stored.
 * \param p_output_size size of the data actually stored into the buffer.
 */
fsal_status_t FSAL_GetXAttrValueById(fsal_handle_t * p_objecthandle,    /* IN */
                                     unsigned int xattr_id,     /* IN */
                                     fsal_op_context_t * p_context,     /* IN */
                                     caddr_t buffer_addr,       /* IN/OUT */
                                     size_t buffer_size,        /* IN */
                                     size_t * p_output_size     /* OUT */
    )
{
  int rc;

  /* sanity checks */
  if(!p_objecthandle || !p_context || !p_output_size || !buffer_addr)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);

  /* check that this index match the type of entry */
  if(xattr_id >= XATTR_COUNT
     || !do_match_type(xattr_list[xattr_id].flags, p_objecthandle->object_type_reminder))
    {
      Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_GetXAttrValue);
    }

  /* get the value */
  rc = xattr_list[xattr_id].get_func(p_objecthandle,
                                     p_context, buffer_addr, buffer_size, p_output_size);

  Return(rc, 0, INDEX_FSAL_GetXAttrValue);

}
示例#7
0
fsal_status_t vfs_getextattr_value_by_id(struct fsal_obj_handle *obj_hdl,
					 const struct req_op_context *opctx,
					 unsigned int xattr_id,
					 caddr_t buffer_addr,
					 size_t buffer_size,
					 size_t *p_output_size)
{
	struct vfs_fsal_obj_handle *obj_handle = NULL;
	int fd = -1;
	int rc = 0;

	obj_handle =
	    container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle);

	/* check that this index match the type of entry */
	if ((xattr_id < XATTR_COUNT)
	    && !do_match_type(xattr_list[xattr_id].flags,
			      obj_hdl->attributes.type)) {
		return fsalstat(ERR_FSAL_INVAL, 0);
	} else if (xattr_id >= XATTR_COUNT) {
		char attr_name[MAXPATHLEN];
		fsal_errors_t fe;

		fd = (obj_hdl->type == DIRECTORY) ?
			vfs_fsal_open(obj_handle, O_DIRECTORY, &fe) :
			vfs_fsal_open(obj_handle, O_RDWR, &fe);
		if (fd < 0)
			return fsalstat(fe, -fd);

		/* get the name for this attr */
		rc = xattr_id_to_name(fd, xattr_id, attr_name);
		if (rc) {
			close(fd);
			return fsalstat(rc, errno);
		}

		rc = fgetxattr(fd, attr_name, buffer_addr, buffer_size);
		if (rc < 0) {
			close(fd);
			return fsalstat(posix2fsal_error(errno), errno);
		}

		/* the xattr value can be a binary, or a string.
		 * trying to determine its type...
		 */
		*p_output_size = rc;

		close(fd);

		rc = ERR_FSAL_NO_ERROR;
	} else {		/* built-in attr */

		/* get the value */
		rc = xattr_list[xattr_id].get_func(obj_hdl, buffer_addr,
						   buffer_size, p_output_size,
						   xattr_list[xattr_id].arg);
	}

	return fsalstat(rc, 0);
}
示例#8
0
fsal_status_t hpss_setextattr_value(struct fsal_obj_handle *fsal_obj_hdl,
				    const char *xattr_name,
				    caddr_t buffer_addr,
				    size_t buffer_size,
				    int create)
{
	struct hpss_fsal_obj_handle *obj_hdl;
	int rc, index;
	sec_cred_t ucreds;
	hpss_userattr_list_t attr;
	char attrpath[MAXNAMLEN];

	if (!fsal_obj_hdl || !xattr_name || !buffer_addr)
		return fsalstat(ERR_FSAL_FAULT, 0);

	if (((char *)buffer_addr)[0] == '\0')
		return fsalstat(ERR_FSAL_NO_ERROR, 0);

	/* check if this is an indexed fake xattr */
	for (index = 0; index < XATTR_COUNT; index++)
		if (do_match_type(xattr_list[index].flags,
				  fsal_obj_hdl->type) &&
		    !strcmp(xattr_list[index].xattr_name, xattr_name))
			return hpss_setextattr_value_by_id(fsal_obj_hdl,
							   index,
							   buffer_addr,
							   buffer_size);

	obj_hdl = container_of(fsal_obj_hdl,
			       struct hpss_fsal_obj_handle,
			       obj_handle);
	  HPSSFSAL_ucreds_from_opctx(op_ctx, &ucreds);

	/* convert FSAL xattr name to HPSS attr path.
	 * returns error if it is not a UDA name.
	 */
	if (fsal_xattr_name_2_uda(xattr_name, attrpath) == 0) {
		attr.len = 1;
		/* use malloc because HPSS may free it */
		attr.Pair = malloc(sizeof(hpss_userattr_t));
		if (attr.Pair == NULL)
			return fsalstat(ERR_FSAL_NOMEM, errno);

		attr.Pair[0].Key = attrpath;
		attr.Pair[0].Value = buffer_addr;

		rc = hpss_UserAttrSetAttrHandle(&(obj_hdl->handle->ns_handle),
						NULL,
						&ucreds,
						&attr,
						UDA_API_VALUE);
		free(attr.Pair);
		if (rc)
			return fsalstat(hpss2fsal_error(rc), rc);
		else
			return fsalstat(ERR_FSAL_INVAL, 0);
	}

	return fsalstat(ERR_FSAL_NO_ERROR, 0);
}
示例#9
0
fsal_status_t tank_getextattr_value_by_id(struct fsal_obj_handle *obj_hdl,
					  unsigned int xattr_id,
					  caddr_t buffer_addr,
					  size_t buffer_size,
					  size_t *p_output_size)
{
	struct zfs_fsal_obj_handle *obj_handle = NULL;
	int retval = -1;
	creden_t cred;

	obj_handle =
	    container_of(obj_hdl, struct zfs_fsal_obj_handle, obj_handle);

	/* sanity checks */
	if (!obj_hdl || !p_output_size || !buffer_addr)
		return fsalstat(ERR_FSAL_FAULT, 0);

	cred.uid = op_ctx->creds->caller_uid;
	cred.gid = op_ctx->creds->caller_gid;

	/* check that this index match the type of entry */
	if ((xattr_id < XATTR_COUNT)
	    && !do_match_type(xattr_list[xattr_id].flags, obj_hdl->type)) {
		return fsalstat(ERR_FSAL_INVAL, 0);
	} else if (xattr_id >= XATTR_COUNT) {
		char attr_name[MAXPATHLEN];

		/* get the name for this attr */
		retval = xattr_id_to_name(ZFSFSAL_GetVFS(obj_handle->handle),
					  &cred,
					  obj_handle->handle->zfs_handle,
					  xattr_id,
					  attr_name);
		if (retval)
			return fsalstat(retval, 0);
		retval = libzfswrap_getxattr(ZFSFSAL_GetVFS(obj_handle->handle),
					     &cred,
					     obj_handle->handle->zfs_handle,
					     attr_name, &buffer_addr);
		if (retval)
			return fsalstat(posix2fsal_error(retval), retval);

		/* the xattr value can be a binary, or a string.
		 * trying to determine its type...
		 */
		*p_output_size = strnlen(buffer_addr, buffer_size);
		xattr_format_value(buffer_addr, p_output_size, buffer_size);

		return fsalstat(ERR_FSAL_NO_ERROR, 0);
	} else {		/* built-in attr */

		/* get the value */
		retval = xattr_list[xattr_id].get_func(obj_hdl, buffer_addr,
						       buffer_size,
						       p_output_size,
						       xattr_list[xattr_id]
						       .arg);
		return fsalstat(retval, 0);
	}
}
示例#10
0
文件: fsal_xattrs.c 项目: ic-hep/emi3
/**
 * Get the value of an extended attribute from its name.
 *
 * \param p_objecthandle Handle of the object you want to get attribute for.
 * \param xattr_name the name of the attribute to be read.
 * \param p_context pointer to the current security context.
 * \param buffer_addr address of the buffer where the xattr value is to be stored.
 * \param buffer_size size of the buffer where the xattr value is to be stored.
 * \param p_output_size size of the data actually stored into the buffer.
 */
fsal_status_t dpmfsal_GetXAttrValueByName(fsal_handle_t * p_objecthandle, // IN
                                          const fsal_name_t * xattr_name, // IN
                                          fsal_op_context_t * p_context, // IN
                                          caddr_t buffer_addr, // IN/OUT
                                          size_t buffer_size, // IN
                                          size_t * p_output_size // OUT
)
{
    unsigned int index;

    LogInfo(COMPONENT_FSAL, "dpmfsal_GetXAttrValueByName: start");

    /* sanity checks */
    if (!p_objecthandle || !p_context || !p_output_size || !buffer_addr
            || !xattr_name)
        Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);

    /* look for this name */

    for (index = 0; index < XATTR_COUNT; index++) {
        if (do_match_type(xattr_list[index].flags,
                p_objecthandle->data.ntype) && !strcmp(
                xattr_list[index].xattr_name, xattr_name->name)) {

            return FSAL_GetXAttrValueById(p_objecthandle, index, p_context,
                    buffer_addr, buffer_size, p_output_size);

        }
    }

    /* not found */
    Return(ERR_FSAL_NOENT, 0, INDEX_FSAL_GetXAttrValue);

}
示例#11
0
/**
 * Get the value of an extended attribute from its name.
 *
 * \param p_objecthandle Handle of the object you want to get attribute for.
 * \param xattr_name the name of the attribute to be read.
 * \param p_context pointer to the current security context.
 * \param buffer_addr address of the buffer where the xattr value is to be stored.
 * \param buffer_size size of the buffer where the xattr value is to be stored.
 * \param p_output_size size of the data actually stored into the buffer.
 */
fsal_status_t ZFSFSAL_GetXAttrValueByName(fsal_handle_t * obj_handle,  /* IN */
                                          const fsal_name_t * xattr_name,  /* IN */
                                          fsal_op_context_t * p_context,   /* IN */
                                          caddr_t buffer_addr,     /* IN/OUT */
                                          size_t buffer_size,      /* IN */
                                          size_t * p_output_size   /* OUT */
    )
{
  unsigned int index;
  char *psz_value;
  int rc;
  creden_t cred;
  zfsfsal_handle_t *p_objecthandle = (zfsfsal_handle_t *)obj_handle;

  /* sanity checks */
  if(!p_objecthandle || !p_context || !p_output_size || !buffer_addr || !xattr_name)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);

  /* look for this name */
  for(index = 0; index < XATTR_COUNT; index++)
    {
      if(do_match_type(xattr_list[index].flags, p_objecthandle->data.type)
         && !strcmp(xattr_list[index].xattr_name, xattr_name->name))
        {

          return ZFSFSAL_GetXAttrValueById((fsal_handle_t *)p_objecthandle, index, p_context, buffer_addr,
                                           buffer_size, p_output_size);
        }
    }

  /* Get the right VFS */
  libzfswrap_vfs_t *p_vfs = ZFSFSAL_GetVFS(p_objecthandle);
  if(!p_vfs)
  {
    ZFSFSAL_VFS_Unlock();
    Return(ERR_FSAL_NOENT, 0, INDEX_FSAL_GetXAttrValue);
  }
  cred.uid = p_context->credential.user;
  cred.gid = p_context->credential.group;

  TakeTokenFSCall();
  if((rc = libzfswrap_getxattr(p_vfs, &cred,
                               p_objecthandle->data.zfs_handle, xattr_name->name, &psz_value)))
  {
    ZFSFSAL_VFS_Unlock();
    Return(posix2fsal_error(rc), 0, INDEX_FSAL_GetXAttrValue);
  }
  ZFSFSAL_VFS_Unlock();

  /* Copy the string (remove this call by changing the libzfswrap API) */
  strncpy(buffer_addr, psz_value, buffer_size);
  buffer_addr[buffer_size - 1] = '\0';
  *p_output_size = strlen(psz_value);
  free(psz_value);

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_GetXAttrValue);

}
示例#12
0
fsal_status_t vfs_getextattr_value_by_name(struct fsal_obj_handle *obj_hdl,
					   const struct req_op_context *opctx,
					   const char *xattr_name,
					   caddr_t buffer_addr,
					   size_t buffer_size,
					   size_t *p_output_size)
{
	struct vfs_fsal_obj_handle *obj_handle = NULL;
	int fd = -1;
	int rc = 0;
	unsigned int index;
	fsal_errors_t fe;

	obj_handle =
	    container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle);


	/* sanity checks */
	if (!obj_hdl || !p_output_size || !buffer_addr || !xattr_name)
		return fsalstat(ERR_FSAL_FAULT, 0);


	/* look for this name */
	for (index = 0; index < XATTR_COUNT; index++) {
		if (do_match_type(xattr_list[index].flags,
				  obj_hdl->attributes.type) &&
		    !strcmp(xattr_list[index].xattr_name, xattr_name)) {
			return vfs_getextattr_value_by_id(obj_hdl, opctx, index,
							  buffer_addr,
							  buffer_size,
							  p_output_size);
		}
	}

	fd = (obj_hdl->type == DIRECTORY) ?
		vfs_fsal_open(obj_handle, O_DIRECTORY, &fe) :
		vfs_fsal_open(obj_handle, O_RDWR, &fe);
	if (fd < 0)
		return fsalstat(fe, -fd);

	/* is it an xattr? */
	rc = fgetxattr(fd, xattr_name, buffer_addr, buffer_size);
	if (rc < 0) {
		close(fd);
		return fsalstat(posix2fsal_error(errno), errno);
	}
	/* the xattr value can be a binary, or a string.
	 * trying to determine its type...
	 */
	*p_output_size = rc;

	close(fd);
	return fsalstat(ERR_FSAL_NO_ERROR, 0);
}
示例#13
0
/**
 * Get the attributes of an extended attribute from its index.
 *
 * \param p_objecthandle Handle of the object you want to get attribute for.
 * \param p_context pointer to the current security context.
 * \param xattr_cookie xattr's cookie (as returned by listxattrs).
 * \param p_attrs xattr's attributes.
 */
fsal_status_t GPFSFSAL_GetXAttrAttrs(fsal_handle_t * p_objecthandle,        /* IN */
                                 fsal_op_context_t * p_context, /* IN */
                                 unsigned int xattr_id, /* IN */
                                 fsal_attrib_list_t * p_attrs
                                          /**< IN/OUT xattr attributes (if supported) */
    )
{
#if 0
  int rc;
  char buff[MAXNAMLEN+1];
  fsal_status_t st;
  fsal_attrib_list_t file_attrs;
#endif

  /* sanity checks */
  if(!p_objecthandle || !p_context || !p_attrs)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrAttrs);

  /* @todo: to be implemented */

  Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_GetXAttrAttrs);
#if 0
  /* check that this index match the type of entry */
  if(xattr_id >= XATTR_COUNT
     || !do_match_type(xattr_list[xattr_id].flags, p_objecthandle->handle.handle_type))
    {
      Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_GetXAttrAttrs);
    }

  /* object attributes we want to retrieve from parent */
  file_attrs.asked_attributes = FSAL_ATTR_MODE | FSAL_ATTR_FILEID | FSAL_ATTR_OWNER
      | FSAL_ATTR_GROUP | FSAL_ATTR_ATIME | FSAL_ATTR_MTIME
      | FSAL_ATTR_CTIME | FSAL_ATTR_CREATION | FSAL_ATTR_CHGTIME | FSAL_ATTR_FSID;

  /* don't retrieve attributes not asked */

  file_attrs.asked_attributes &= p_attrs->asked_attributes;

  st = GPFSFSAL_getattrs(p_objecthandle, p_context, &file_attrs);

  if(FSAL_IS_ERROR(st))
    Return(st.major, st.minor, INDEX_FSAL_GetXAttrAttrs);

  if((rc = file_attributes_to_xattr_attrs(&file_attrs, p_attrs, xattr_id)))
    {
      Return(ERR_FSAL_INVAL, rc, INDEX_FSAL_GetXAttrAttrs);
    }

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_GetXAttrAttrs);
#endif

}                               /* FSAL_GetXAttrAttrs */
示例#14
0
fsal_status_t tank_getextattr_value_by_name(struct fsal_obj_handle *obj_hdl,
					    const char *xattr_name,
					    caddr_t buffer_addr,
					    size_t buffer_size,
					    size_t *p_output_size)
{
	struct zfs_fsal_obj_handle *obj_handle = NULL;
	unsigned int index;
	creden_t cred;
	int retval = 0;

	obj_handle =
	    container_of(obj_hdl, struct zfs_fsal_obj_handle, obj_handle);

	/* sanity checks */
	if (!obj_hdl || !p_output_size || !buffer_addr || !xattr_name)
		return fsalstat(ERR_FSAL_FAULT, 0);

	cred.uid = op_ctx->creds->caller_uid;
	cred.gid = op_ctx->creds->caller_gid;

	/* look for this name */
	for (index = 0; index < XATTR_COUNT; index++) {
		if (do_match_type(xattr_list[index].flags,
				  obj_hdl->attributes.type)
		    && !strcmp(xattr_list[index].xattr_name,
			       xattr_name)) {
			return tank_getextattr_value_by_id(obj_hdl,
							   index, buffer_addr,
							   buffer_size,
							   p_output_size);
		}
	}

	/* is it an xattr? */
	retval = libzfswrap_getxattr(ZFSFSAL_GetVFS(obj_handle->handle),
				     &cred,
				     obj_handle->handle->zfs_handle,
				     xattr_name,
				     &buffer_addr);
	if (retval)
		return fsalstat(posix2fsal_error(retval), retval);
	/* the xattr value can be a binary, or a string.
	 * trying to determine its type...
	 */
	*p_output_size = strnlen(buffer_addr, buffer_size);
	xattr_format_value(buffer_addr, p_output_size, buffer_size);

	return fsalstat(ERR_FSAL_NO_ERROR, 0);
}
示例#15
0
/**
 * Get the attributes of an extended attribute from its index.
 *
 * \param p_objecthandle Handle of the object you want to get attribute for.
 * \param p_context pointer to the current security context.
 * \param xattr_cookie xattr's cookie (as returned by listxattrs).
 * \param p_attrs xattr's attributes.
 */
fsal_status_t ZFSFSAL_GetXAttrAttrs(fsal_handle_t * p_objecthandle,        /* IN */
                                    fsal_op_context_t * p_context, /* IN */
                                    unsigned int xattr_id, /* IN */
                                    fsal_attrib_list_t * p_attrs
                                          /**< IN/OUT xattr attributes (if supported) */
    )
{
  int rc;
  fsal_status_t st;
  fsal_attrib_list_t file_attrs;

  /* sanity checks */
  if(!p_objecthandle || !p_context || !p_attrs)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrAttrs);

  /* object attributes we want to retrieve from parent */
  file_attrs.asked_attributes = FSAL_ATTR_MODE | FSAL_ATTR_FILEID | FSAL_ATTR_OWNER
      | FSAL_ATTR_GROUP | FSAL_ATTR_ATIME | FSAL_ATTR_MTIME | FSAL_ATTR_TYPE
      | FSAL_ATTR_CTIME | FSAL_ATTR_CREATION | FSAL_ATTR_CHGTIME | FSAL_ATTR_FSID;

  /* don't retrieve attributes not asked */
  file_attrs.asked_attributes &= p_attrs->asked_attributes;

  st = ZFSFSAL_getattrs(p_objecthandle, p_context, &file_attrs);

  if(FSAL_IS_ERROR(st))
    Return(st.major, st.minor, INDEX_FSAL_GetXAttrAttrs);

  /* check that this index match the type of entry */
  if(xattr_id < XATTR_COUNT
     && !do_match_type(xattr_list[xattr_id].flags, file_attrs.type))
    {
      Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_GetXAttrAttrs);
    }
  else if(xattr_id >= XATTR_COUNT)
    {
      /* This is user defined xattr */
      LogFullDebug(COMPONENT_FSAL,
                        "Getting attributes for xattr #%u", xattr_id - XATTR_COUNT);
    }

  if((rc = file_attributes_to_xattr_attrs(&file_attrs, p_attrs, xattr_id)))
    {
      Return(ERR_FSAL_INVAL, rc, INDEX_FSAL_GetXAttrAttrs);
    }

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_GetXAttrAttrs);

}
示例#16
0
/**
 * Get the attributes of an extended attribute from its index.
 *
 * \param p_objecthandle Handle of the object you want to get attribute for.
 * \param p_context pointer to the current security context.
 * \param xattr_cookie xattr's cookie (as returned by listxattrs).
 * \param p_attrs xattr's attributes.
 */
fsal_status_t POSIXFSAL_GetXAttrAttrs(fsal_handle_t * objecthandle,      /* IN */
                                      fsal_op_context_t * context,       /* IN */
                                      unsigned int xattr_id,    /* IN */
                                      fsal_attrib_list_t * p_attrs
                                          /**< IN/OUT xattr attributes (if supported) */
    )
{
  posixfsal_handle_t * p_objecthandle = (posixfsal_handle_t *) objecthandle;
  posixfsal_op_context_t * p_context = (posixfsal_op_context_t *) context;
  int rc;
  fsal_status_t st;
  fsal_attrib_list_t file_attrs;

  /* sanity checks */
  if(!p_objecthandle || !p_context || !p_attrs)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrAttrs);

  /* check that this index match the type of entry */
  if(xattr_id >= XATTR_COUNT
     || !do_match_type(xattr_list[xattr_id].flags, p_objecthandle->data.info.ftype))
    {
      Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_GetXAttrAttrs);
    }

  /* object attributes we want to retrieve from parent */
  file_attrs.asked_attributes = FSAL_ATTR_MODE | FSAL_ATTR_FILEID | FSAL_ATTR_OWNER
      | FSAL_ATTR_GROUP | FSAL_ATTR_ATIME | FSAL_ATTR_MTIME
      | FSAL_ATTR_CTIME | FSAL_ATTR_CREATION | FSAL_ATTR_CHGTIME | FSAL_ATTR_FSID;

  /* don't retrieve attributes not asked */

  file_attrs.asked_attributes &= p_attrs->asked_attributes;

  st = POSIXFSAL_getattrs(objecthandle, context, &file_attrs);

  if(FSAL_IS_ERROR(st))
    Return(st.major, st.minor, INDEX_FSAL_GetXAttrAttrs);

  if((rc = file_attributes_to_xattr_attrs(&file_attrs, p_attrs, xattr_id)))
    {
      Return(ERR_FSAL_INVAL, rc, INDEX_FSAL_GetXAttrAttrs);
    }

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_GetXAttrAttrs);

}                               /* FSAL_GetXAttrAttrs */
示例#17
0
/**
 * Get the value of an extended attribute from its index.
 *
 * \param p_objecthandle Handle of the object you want to get attribute for.
 * \param xattr_name the name of the attribute to be read.
 * \param p_context pointer to the current security context.
 * \param buffer_addr address of the buffer where the xattr value is to be stored.
 * \param buffer_size size of the buffer where the xattr value is to be stored.
 * \param p_output_size size of the data actually stored into the buffer.
 */
fsal_status_t POSIXFSAL_GetXAttrValueById(fsal_handle_t * objecthandle,  /* IN */
                                          unsigned int xattr_id,        /* IN */
                                          fsal_op_context_t * context,   /* IN */
                                          caddr_t buffer_addr,  /* IN/OUT */
                                          size_t buffer_size,   /* IN */
                                          size_t * p_output_size        /* OUT */
    )
{
  posixfsal_handle_t * p_objecthandle = (posixfsal_handle_t *) objecthandle;
  posixfsal_op_context_t * p_context = (posixfsal_op_context_t *) context;
  int rc;
  char buff[MAXNAMLEN];

  /* sanity checks */
  if(!p_objecthandle || !p_context || !p_output_size || !buffer_addr)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);

  /* check that this index match the type of entry */
  if(xattr_id >= XATTR_COUNT
     || !do_match_type(xattr_list[xattr_id].flags, p_objecthandle->data.info.ftype))
    {
      Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_GetXAttrValue);
    }

  /* get the value */
  if(xattr_list[xattr_id].print_func == NULL)
    {
      rc = xattr_list[xattr_id].get_func(p_objecthandle,
                                         p_context,
                                         buffer_addr, buffer_size, p_output_size);
    }
  else
    {
      rc = xattr_list[xattr_id].get_func(p_objecthandle,
                                         p_context, buff, MAXNAMLEN, p_output_size);

      xattr_list[xattr_id].print_func(buff, MAXNAMLEN, buffer_addr, p_output_size);
    }

  Return(rc, 0, INDEX_FSAL_GetXAttrValue);
}
示例#18
0
fsal_status_t vfs_list_ext_attrs(struct fsal_obj_handle *obj_hdl,
				 const struct req_op_context *opctx,
				 unsigned int argcookie,
				 fsal_xattrent_t *xattrs_tab,
				 unsigned int xattrs_tabsize,
				 unsigned int *p_nb_returned, int *end_of_list)
{
	unsigned int index;
	unsigned int out_index;
	unsigned int cookie = argcookie;
	struct vfs_fsal_obj_handle *obj_handle = NULL;
	int fd = -1;
	fsal_errors_t fe;

	char names[MAXPATHLEN], *ptr;
	ssize_t namesize;
	int xattr_idx;

	obj_handle =
	    container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle);

	/* Deal with special cookie */
	if (cookie == XATTR_RW_COOKIE)
		cookie = XATTR_COUNT;

	for (index = cookie, out_index = 0;
	     index < XATTR_COUNT && out_index < xattrs_tabsize; index++) {
		if (do_match_type
		    (xattr_list[index].flags, obj_hdl->attributes.type)) {
			/* fills an xattr entry */
			xattrs_tab[out_index].xattr_id = index;
			strncpy(xattr_list[index].xattr_name,
				xattrs_tab[out_index].xattr_name, MAXNAMLEN);
			xattrs_tab[out_index].xattr_cookie = index + 1;

			/* set asked attributes (all supported) */
			xattrs_tab[out_index].attributes.mask =
			    obj_hdl->attributes.mask;

			if (file_attributes_to_xattr_attrs
			    (&obj_hdl->attributes,
			     &xattrs_tab[out_index].attributes, index)) {
				/* set error flag */
				xattrs_tab[out_index].attributes.mask =
				    ATTR_RDATTR_ERR;
			}

			/* next output slot */
			out_index++;
		}
	}

	/* save a call if output array is full */
	if (out_index == xattrs_tabsize) {
		*end_of_list = FALSE;
		*p_nb_returned = out_index;
		return fsalstat(ERR_FSAL_NO_ERROR, 0);
	}

	/* get the path of the file in Lustre */
	fd = (obj_hdl->type == DIRECTORY) ?
		vfs_fsal_open(obj_handle, O_DIRECTORY, &fe) :
		vfs_fsal_open(obj_handle, O_RDWR, &fe);
	if (fd < 0)
		return fsalstat(fe, -fd);

	/* get xattrs */

	namesize = flistxattr(fd, names, sizeof(names));

	if (namesize >= 0) {
		size_t len = 0;

		errno = 0;

		for (ptr = names, xattr_idx = 0;
		     (ptr < names + namesize) && (out_index < xattrs_tabsize);
		     xattr_idx++, ptr += len + 1) {
			len = strlen(ptr);
			index = XATTR_COUNT + xattr_idx;

			/* skip if index is before cookie */
			if (index < cookie)
				continue;

			/* fills an xattr entry */
			xattrs_tab[out_index].xattr_id = index;
			strncpy(xattrs_tab[out_index].xattr_name, ptr, len + 1);
			xattrs_tab[out_index].xattr_cookie = index + 1;

			/* set asked attributes (all supported) */
			xattrs_tab[out_index].attributes.mask =
			    obj_hdl->attributes.mask;

			if (file_attributes_to_xattr_attrs
			    (&obj_hdl->attributes,
			     &xattrs_tab[out_index].attributes, index)) {
				/* set error flag */
				xattrs_tab[out_index].attributes.mask =
				    ATTR_RDATTR_ERR;
			}

			/* next output slot */
			out_index++;
		}
		/* all xattrs are in the output array */
		if (ptr >= names + namesize)
			*end_of_list = TRUE;
		else
			*end_of_list = FALSE;
	} else			/* no xattrs */
		*end_of_list = TRUE;

	*p_nb_returned = out_index;

	close(fd);
	return fsalstat(ERR_FSAL_NO_ERROR, 0);
}
示例#19
0
fsal_status_t tank_list_ext_attrs(struct fsal_obj_handle *obj_hdl,
				  unsigned int argcookie,
				  fsal_xattrent_t *xattrs_tab,
				  unsigned int xattrs_tabsize,
				  unsigned int *p_nb_returned, int *end_of_list)
{
	unsigned int index;
	unsigned int out_index;
	unsigned int cookie = argcookie;
	struct zfs_fsal_obj_handle *obj_handle = NULL;

	char names[MAXPATHLEN], *ptr;
	size_t namesize;
	int xattr_idx;
	int retval;
	creden_t cred;

	/* sanity checks */
	if (!obj_hdl || !xattrs_tab || !p_nb_returned || !end_of_list)
		return fsalstat(ERR_FSAL_FAULT, 0);

	obj_handle =
	    container_of(obj_hdl, struct zfs_fsal_obj_handle, obj_handle);

	cred.uid = op_ctx->creds->caller_uid;
	cred.gid = op_ctx->creds->caller_gid;

	/* Deal with special cookie */
	if (cookie == XATTR_RW_COOKIE)
		cookie = XATTR_COUNT;

	for (index = cookie, out_index = 0;
	     index < XATTR_COUNT && out_index < xattrs_tabsize; index++) {
		if (do_match_type(xattr_list[index].flags,
				  obj_hdl->attributes.type)) {
			/* fills an xattr entry */
			xattrs_tab[out_index].xattr_id = index;
			strncpy(xattr_list[index].xattr_name,
				xattrs_tab[out_index].xattr_name, MAXNAMLEN);
			xattr_list[index].xattr_name[MAXNAMLEN] = '\0';
			xattrs_tab[out_index].xattr_cookie = index + 1;

			/* set asked attributes (all supported) */
			xattrs_tab[out_index].attributes.mask =
			    obj_hdl->attributes.mask;

			if (file_attributes_to_xattr_attrs(&obj_hdl->attributes,
							   &xattrs_tab
							   [out_index]
							   .attributes,
							   index)) {
				/* set error flag */
				xattrs_tab[out_index].attributes.mask =
				    ATTR_RDATTR_ERR;
			}

			/* next output slot */
			out_index++;
		}
	}

	/* save a call if output array is full */
	if (out_index == xattrs_tabsize) {
		*end_of_list = false;
		*p_nb_returned = out_index;
		return fsalstat(ERR_FSAL_NO_ERROR, 0);
	}

	/* get the path of the file in Lustre */

	/* get xattrs */

	retval = libzfswrap_listxattr(ZFSFSAL_GetVFS(obj_handle->handle),
				      &cred,
				      obj_handle->handle->zfs_handle,
				      (char **)&names, &namesize);
	if (retval)
		return fsalstat(posix2fsal_error(retval), retval);

	if (namesize > 0) {
		size_t len = 0;

		errno = 0;

		for (ptr = names, xattr_idx = 0;
		     (ptr < names + namesize) && (out_index < xattrs_tabsize);
		     xattr_idx++, ptr += len + 1) {
			len = strlen(ptr);
			index = XATTR_COUNT + xattr_idx;

			/* skip if index is before cookie */
			if (index < cookie)
				continue;

			/* fills an xattr entry */
			xattrs_tab[out_index].xattr_id = index;
			strncpy(xattrs_tab[out_index].xattr_name, ptr, len + 1);
			xattrs_tab[out_index].xattr_cookie = index + 1;

			/* set asked attributes (all supported) */
			xattrs_tab[out_index].attributes.mask =
			    obj_hdl->attributes.mask;

			if (file_attributes_to_xattr_attrs
			    (&obj_hdl->attributes,
			     &xattrs_tab[out_index].attributes, index)) {
				/* set error flag */
				xattrs_tab[out_index].attributes.mask =
				    ATTR_RDATTR_ERR;
			}

			/* next output slot */
			out_index++;
		}
		/* all xattrs are in the output array */
		if (ptr >= names + namesize)
			*end_of_list = true;
		else
			*end_of_list = false;
	} else			/* no xattrs */
		*end_of_list = true;

	*p_nb_returned = out_index;

	return fsalstat(ERR_FSAL_NO_ERROR, 0);
}
示例#20
0
/**
 * Retrieves the list of extended attributes for an object in the filesystem.
 * 
 * \param p_objecthandle Handle of the object we want to get extended attributes.
 * \param cookie index of the next entry to be returned.
 * \param p_context pointer to the current security context.
 * \param xattrs_tab a table for storing extended attributes list to.
 * \param xattrs_tabsize the maximum number of xattr entries that xattrs_tab
 *            can contain.
 * \param p_nb_returned the number of xattr entries actually stored in xattrs_tab.
 * \param end_of_list this boolean indicates that the end of xattrs list has been reached.
 */
fsal_status_t GPFSFSAL_ListXAttrs(fsal_handle_t * p_objecthandle,   /* IN */
                              unsigned int cookie,      /* IN */
                              fsal_op_context_t * p_context,    /* IN */
                              fsal_xattrent_t * xattrs_tab,     /* IN/OUT */
                              unsigned int xattrs_tabsize,      /* IN */
                              unsigned int *p_nb_returned,      /* OUT */
                              int *end_of_list  /* OUT */
    )
{
#if 0
  int rc;
  unsigned int index;
  unsigned int out_index;
  char object_path[FSAL_MAX_PATH_LEN];
  fsal_status_t st;
  fsal_attrib_list_t file_attrs;
#endif

  /* sanity checks */
  if(!p_objecthandle || !p_context || !xattrs_tab || !p_nb_returned || !end_of_list)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_ListXAttrs);

  /* @todo: to be implemented */

  Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_ListXAttrs);

#if 0

  /* object attributes we want to retrieve from parent */
  file_attrs.asked_attributes = FSAL_ATTR_MODE | FSAL_ATTR_FILEID | FSAL_ATTR_OWNER
      | FSAL_ATTR_GROUP | FSAL_ATTR_ATIME | FSAL_ATTR_MTIME
      | FSAL_ATTR_CTIME | FSAL_ATTR_CREATION | FSAL_ATTR_CHGTIME | FSAL_ATTR_FSID;

  /* don't retrieve unsuipported attributes */
  file_attrs.asked_attributes &= global_fs_info.supported_attrs;

  st = GPFSFSAL_getattrs(p_objecthandle, p_context, &file_attrs);

  if(FSAL_IS_ERROR(st))
    Return(st.major, st.minor, INDEX_FSAL_ListXAttrs);

  for(index = cookie, out_index = 0;
      index < XATTR_COUNT && out_index < xattrs_tabsize; index++)
    {
      if(do_match_type(xattr_list[index].flags, p_objecthandle->handle.handle_type))
        {
          /* fills an xattr entry */
          xattrs_tab[out_index].xattr_id = index;
          FSAL_str2name(xattr_list[index].xattr_name, 0,
                        &xattrs_tab[out_index].xattr_name);
          xattrs_tab[out_index].xattr_cookie = index + 1;

          /* set asked attributes (all supported) */
          xattrs_tab[out_index].attributes.asked_attributes =
              global_fs_info.supported_attrs;

          if(file_attributes_to_xattr_attrs
             (&file_attrs, &xattrs_tab[out_index].attributes, index))
            {
              /* set error flag */
              xattrs_tab[out_index].attributes.asked_attributes = FSAL_ATTR_RDATTR_ERR;
            }

          /* next output slot */
          out_index++;
        }
    }

  *p_nb_returned = out_index;
  *end_of_list = (index == XATTR_COUNT);

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_ListXAttrs);
#endif

}
示例#21
0
fsal_status_t hpss_getextattr_value_by_name(
				struct fsal_obj_handle *fsal_obj_hdl,
				const char *xattr_name,
				caddr_t buffer_addr,
				size_t buffer_size,
				size_t *p_output_size)
{
	struct hpss_fsal_obj_handle *obj_hdl;
	int rc, index;
	sec_cred_t ucreds;
	hpss_userattr_list_t attr;
	char attrpath[MAXNAMLEN];
	char attrval[MAXPATHLEN];

	if (!fsal_obj_hdl || !p_output_size)
		return fsalstat(ERR_FSAL_FAULT, 0);

	/* check if this is an indexed fake xattr */
	for (index = 0; index < XATTR_COUNT; index++)
		if (do_match_type(xattr_list[index].flags,
				  fsal_obj_hdl->type)
		    && !strcmp(xattr_list[index].xattr_name, xattr_name))
			return hpss_getextattr_value_by_id(fsal_obj_hdl,
							   index,
							   buffer_addr,
							   buffer_size,
							   p_output_size);

	obj_hdl =
		 container_of(fsal_obj_hdl,
			      struct hpss_fsal_obj_handle,
			      obj_handle);
	HPSSFSAL_ucreds_from_opctx(op_ctx, &ucreds);


	if (fsal_xattr_name_2_uda(xattr_name, attrpath) == 0) {
		attr.len = 1;
		/* use malloc because HPSS may free it */
		attr.Pair = malloc(sizeof(hpss_userattr_t));
		if (attr.Pair == NULL)
			return fsalstat(ERR_FSAL_NOMEM, errno);

		attr.Pair[0].Key = attrpath;
		attr.Pair[0].Value = attrval;

		rc = hpss_UserAttrGetAttrHandle(&(obj_hdl->handle->ns_handle),
						NULL,
						&ucreds,
						&attr,
						UDA_API_VALUE);
		if (rc) {
			free(attr.Pair);
			return fsalstat(hpss2fsal_error(rc), rc);
		}

		if (attr.len > 0) {
			if (attr.Pair[0].Value != NULL) {
				char *noxml = hpss_ChompXMLHeader(
							attr.Pair[0].Value,
							NULL);
				strcpy(attrval, noxml);
				free(noxml);
				strncpy((char *)buffer_addr,
					 attrval,
					 buffer_size);
				*p_output_size = strlen(attrval) + 1;
			} else {
				strcpy((char *)buffer_addr, "");
				*p_output_size = 1;
			}

			free(attr.Pair);
			rc = 0;
		} else {
			free(attr.Pair);
			rc = ERR_FSAL_NOENT;
		}
	}

	return fsalstat(rc, 0);
}
示例#22
0
fsal_status_t hpss_getextattr_value_by_id(struct fsal_obj_handle *fsal_obj_hdl,
					  unsigned int xattr_id,
					  caddr_t buffer_addr,
					  size_t buffer_size,
					  size_t *p_output_size)
{
	struct hpss_fsal_obj_handle *obj_hdl;
	int rc, i;
	sec_cred_t ucreds;
	hpss_userattr_list_t attr_list;

	if (!fsal_obj_hdl || !p_output_size)
		return fsalstat(ERR_FSAL_FAULT, 0);

	obj_hdl = container_of(fsal_obj_hdl,
			       struct hpss_fsal_obj_handle,
			       obj_handle);
	HPSSFSAL_ucreds_from_opctx(op_ctx, &ucreds);

	/* check that this index match the type of entry */
	if (xattr_id < XATTR_COUNT) {
		if (!do_match_type(xattr_list[xattr_id].flags,
				   fsal_obj_hdl->type))
			return fsalstat(ERR_FSAL_INVAL, 0);

	rc = xattr_list[xattr_id].get_func(fsal_obj_hdl,
					   buffer_addr,
					   buffer_size,
					   p_output_size,
					   &ucreds);
	} else
		if (xattr_id >= XATTR_COUNT) {
			memset(&attr_list, 0, sizeof(hpss_userattr_list_t));

			LogFullDebug(COMPONENT_FSAL,
				     "Getting value for UDA #%u",
				     xattr_id - XATTR_COUNT);

		/* get list of UDAs for this entry, and
		 * return the good value */
		rc = hpss_UserAttrListAttrHandle(&(obj_hdl->handle->ns_handle),
						 NULL,
						 &ucreds,
						 &attr_list,
						 XML_ATTR);

		if (rc != 0)
			return fsalstat(hpss2fsal_error(rc), rc);

		else
			if (xattr_id - XATTR_COUNT >= attr_list.len)
				return fsalstat(ERR_FSAL_STALE, 0);

		if ((attr_list.Pair[xattr_id - XATTR_COUNT].Value != NULL) &&
		    (attr_list.Pair[xattr_id - XATTR_COUNT].Value[0] != '\0'))
			*p_output_size =
				 snprintf((char *)buffer_addr,
					  buffer_size, "%s\n",
			attr_list.Pair[xattr_id - XATTR_COUNT].Value);
		else {
			((char *)buffer_addr)[0] = '\0';
			*p_output_size = 0;
		}

		/* Allocated by hpss - use free */
		for (i = 0; i < attr_list.len; i++) {
			free(attr_list.Pair[i].Key);
			free(attr_list.Pair[i].Value);
		}
		free(attr_list.Pair);

		return fsalstat(ERR_FSAL_NO_ERROR, 0);
	}
	return fsalstat(rc, 0);
}
示例#23
0
fsal_status_t hpss_getextattr_id_by_name(struct fsal_obj_handle *fsal_obj_hdl,
					 const char *xattr_name,
					 unsigned int *pxattr_id)
{
	struct hpss_fsal_obj_handle *obj_hdl;
	unsigned int index;
	int found = FALSE;

	if (!fsal_obj_hdl || !xattr_name || !pxattr_id)
		return fsalstat(ERR_FSAL_FAULT, 0);

	obj_hdl = container_of(fsal_obj_hdl,
			       struct hpss_fsal_obj_handle,
			       obj_handle);

	for (index = 0; index < XATTR_COUNT; index++) {
		if (do_match_type(xattr_list[index].flags,
				  fsal_obj_hdl->type) &&
		    !strcmp(xattr_list[index].xattr_name,
			    xattr_name)) {
			found = TRUE;
			break;
		}
	}

	if (!found) {
		/* search for name in UDAs */
		hpss_userattr_list_t attr_list;
		unsigned int i;
		int rc;
		char attrpath[MAXNAMLEN];
		sec_cred_t ucreds;

		HPSSFSAL_ucreds_from_opctx(op_ctx, &ucreds);

		/* convert FSAL xattr name to HPSS attr path.
		 * returns error if it is not a UDA name.
		 */
		if (fsal_xattr_name_2_uda(xattr_name,
					  attrpath) == 0) {
			memset(&attr_list, 0, sizeof(hpss_userattr_list_t));

			LogFullDebug(COMPONENT_FSAL,
				     "looking for xattr '%s' in UDAs",
				     xattr_name);

		/* get list of UDAs, and return the good index*/

		rc = hpss_UserAttrListAttrHandle(&(obj_hdl->handle->ns_handle),
						 NULL,
						 &ucreds,
						 &attr_list,
						 XML_ATTR);

		if (rc == 0)
			for (i = 0; i < attr_list.len; i++)
				if (!strcmp(attr_list.Pair[i].Key, attrpath)) {
					/* xattr index is XATTR_COUNT +
					 * UDA index */
					index = XATTR_COUNT + i;
					found = TRUE;
					break;
				}

		/* Allocated by hpss - use free */
		for (i = 0; i < attr_list.len; i++) {
			free(attr_list.Pair[i].Key);
			free(attr_list.Pair[i].Value);
		}
		free(attr_list.Pair);
		}
	}

	if (found) {
		*pxattr_id = index;
		return fsalstat(ERR_FSAL_NO_ERROR, 0);
	} else
		return fsalstat(ERR_FSAL_NOENT, ENOENT);
}
示例#24
0
fsal_status_t hpss_list_ext_attrs(struct fsal_obj_handle *fsal_obj_hdl,
				  unsigned int cookie,
				  fsal_xattrent_t *xattrs_tab,
				  unsigned int xattrs_tabsize,
				  unsigned int *p_nb_returned,
				  int *end_of_list)
{
	struct hpss_fsal_obj_handle *obj_hdl;
	int index, out_index, rc;
	sec_cred_t ucreds;
	hpss_userattr_list_t attr_list;

	if (!fsal_obj_hdl || !xattrs_tab || !p_nb_returned || !end_of_list)
		return fsalstat(ERR_FSAL_FAULT, 0);

	obj_hdl = container_of(fsal_obj_hdl,
			       struct hpss_fsal_obj_handle,
			       obj_handle);
	HPSSFSAL_ucreds_from_opctx(op_ctx, &ucreds);

	for (index = cookie,
	     out_index = 0;
	     index < XATTR_COUNT && out_index < xattrs_tabsize; index++) {
		if (do_match_type(xattr_list[index].flags,
				  fsal_obj_hdl->type)) {

			/* fills an xattr entry */
			xattrs_tab[out_index].xattr_id = index;
			memcpy(xattrs_tab[out_index].xattr_name,
			       xattr_list[index].xattr_name,
			       strlen(xattr_list[index].xattr_name)+1);
			xattrs_tab[out_index].xattr_cookie = index + 1;

			/* set asked attributes */
			file_attributes_to_xattr_attrs(
					&obj_hdl->attributes,
					&xattrs_tab[out_index].attributes,
					index);

			/* next output slot */
			out_index++;
		}
	}

	/* save a call if output array is full */
	if (out_index == xattrs_tabsize) {
		*end_of_list = FALSE;
		*p_nb_returned = out_index;

		return fsalstat(ERR_FSAL_NO_ERROR, 0);
	}

	/* get list of UDAs for this entry */
	memset(&attr_list, 0, sizeof(hpss_userattr_list_t));

	rc = hpss_UserAttrListAttrHandle(&(obj_hdl->handle->ns_handle),
					 NULL,
					 &ucreds,
					 &attr_list,
					 XML_ATTR);

	if (rc == -ENOENT)
		attr_list.len = 0;
	else
		if (rc)
			return fsalstat(hpss2fsal_error(rc), -rc);

	unsigned int i;

	for (i = 0; (i < attr_list.len) && (out_index < xattrs_tabsize); i++) {
		char attr_name[MAXNAMLEN];

		/* the id is XATTR_COUNT + index of HPSS UDA */
		index = XATTR_COUNT + i;

		/* continue while index < cookie */
		if (index < cookie)
			continue;

		xattrs_tab[out_index].xattr_id = index;

		if (strlen(attr_list.Pair[i].Key) >= MAXNAMLEN)
			return fsalstat(ERR_FSAL_NAMETOOLONG, 0);

		/* HPSS UDAs namespace is slash-separated.
		 * we convert '/' to '.'
		 */
		rc = hpss_uda_name_2_fsal(attr_list.Pair[i].Key, attr_name);

		if (rc != ERR_FSAL_NO_ERROR)
			return fsalstat(rc, 0);

		memcpy(xattrs_tab[out_index].xattr_name,
		       attr_name,
		       strlen(attr_name)+1);
		xattrs_tab[out_index].xattr_cookie = index + 1;

		/* set asked attributes */
		file_attributes_to_xattr_attrs(
					&obj_hdl->attributes,
					&xattrs_tab[out_index].attributes,
					index);

		/* we know the size here (+2 for \n\0) */
		if (attr_list.Pair[i].Value != NULL)
			xattrs_tab[out_index].attributes.filesize =
				 strlen(attr_list.Pair[i].Value) + 2;

	      /* next output slot */
	      out_index++;
	}

	/* Allocated by hpss - use free */
	for (index = 0; index < attr_list.len; index++) {
		free(attr_list.Pair[index].Key);
		free(attr_list.Pair[index].Value);
	}
	free(attr_list.Pair);

	/* not end of list if there is more UDAs */
	if (i < attr_list.len)
		*end_of_list = FALSE;
	else
		*end_of_list = TRUE;

	*p_nb_returned = out_index;

	return fsalstat(ERR_FSAL_NO_ERROR, 0);
}
示例#25
0
/**
 * Get the value of an extended attribute from its index.
 *
 * \param p_objecthandle Handle of the object you want to get attribute for.
 * \param xattr_name the name of the attribute to be read.
 * \param p_context pointer to the current security context.
 * \param buffer_addr address of the buffer where the xattr value is to be stored.
 * \param buffer_size size of the buffer where the xattr value is to be stored.
 * \param p_output_size size of the data actually stored into the buffer.
 */
fsal_status_t ZFSFSAL_GetXAttrValueById(fsal_handle_t * obj_handle,    /* IN */
                                     unsigned int xattr_id,     /* IN */
                                     fsal_op_context_t * context,     /* IN */
                                     caddr_t buffer_addr,       /* IN/OUT */
                                     size_t buffer_size,        /* IN */
                                     size_t * p_output_size     /* OUT */
    )
{
  int rc;
  char buff[MAXNAMLEN];
  zfsfsal_handle_t *p_objecthandle = (zfsfsal_handle_t *)obj_handle;
  zfsfsal_op_context_t *p_context = (zfsfsal_op_context_t *)context;

  /* sanity checks */
  if(!p_objecthandle || !p_context || !p_output_size || !buffer_addr)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);

  /* check that this index match the type of entry */
  if(xattr_id < XATTR_COUNT
     && !do_match_type(xattr_list[xattr_id].flags, p_objecthandle->data.type))
  {
    Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_GetXAttrValue);
  }

  /* Get the right VFS */
  ZFSFSAL_VFS_RDLock();
  libzfswrap_vfs_t *p_vfs = ZFSFSAL_GetVFS(p_objecthandle);
  if(!p_vfs)
  {
    ZFSFSAL_VFS_Unlock();
    Return(ERR_FSAL_NOENT, 0, INDEX_FSAL_GetXAttrValue);
  }

  if(xattr_id >= XATTR_COUNT)
  {
    char psz_attr_name[MAXPATHLEN];
    char *psz_value;
    creden_t cred;

    if((rc = xattr_id_to_name(p_vfs, p_context, p_objecthandle, xattr_id, psz_attr_name)))
    {
      ZFSFSAL_VFS_Unlock();
      Return(rc, errno, INDEX_FSAL_GetXAttrValue);
    }
    cred.uid = p_context->credential.user;
    cred.gid = p_context->credential.group;

    if((rc = libzfswrap_getxattr(p_vfs, &cred,
                                 p_objecthandle->data.zfs_handle, psz_attr_name, &psz_value)))
    {
      ZFSFSAL_VFS_Unlock();
      Return(posix2fsal_error(rc), 0, INDEX_FSAL_GetXAttrValue);
    }

    /* Copy the string (remove this call by changing the libzfswrap API) */
    strncpy(buffer_addr, psz_value, buffer_size);
    buffer_addr[buffer_size - 1] = '\0';
    *p_output_size = strlen(psz_value);
    free(psz_value);
  }
  else
  {
    rc = xattr_list[xattr_id].get_func(p_objecthandle, p_context,
                                       buffer_addr, buffer_size,
                                       p_output_size);
    /* Get the value */
    if(xattr_list[xattr_id].print_func == NULL)
      rc = xattr_list[xattr_id].get_func(p_objecthandle, p_context,
                                         buffer_addr, buffer_size, p_output_size);
    else
    {
      rc = xattr_list[xattr_id].get_func(p_objecthandle, p_context,
                                         buff, MAXNAMLEN, p_output_size);
      xattr_list[xattr_id].print_func(buff, MAXNAMLEN, buffer_addr, p_output_size);
    }
  }

  ZFSFSAL_VFS_Unlock();
  Return(rc, 0, INDEX_FSAL_GetXAttrValue);
}
示例#26
0
/**
 * Retrieves the list of extended attributes for an object in the filesystem.
 * 
 * \param p_objecthandle Handle of the object we want to get extended attributes.
 * \param cookie index of the next entry to be returned.
 * \param p_context pointer to the current security context.
 * \param xattrs_tab a table for storing extended attributes list to.
 * \param xattrs_tabsize the maximum number of xattr entries that xattrs_tab
 *            can contain.
 * \param p_nb_returned the number of xattr entries actually stored in xattrs_tab.
 * \param end_of_list this boolean indicates that the end of xattrs list has been reached.
 */
fsal_status_t ZFSFSAL_ListXAttrs(fsal_handle_t * obj_handle,   /* IN */
                              unsigned int argcookie,      /* IN */
                              fsal_op_context_t * p_context,    /* IN */
                              fsal_xattrent_t * xattrs_tab,     /* IN/OUT */
                              unsigned int xattrs_tabsize,      /* IN */
                              unsigned int *p_nb_returned,      /* OUT */
                              int *end_of_list  /* OUT */
    )
{
  unsigned int index;
  unsigned int out_index;
  fsal_status_t st;
  fsal_attrib_list_t file_attrs;
  int rc;
  creden_t cred;
  zfsfsal_handle_t *p_objecthandle = (zfsfsal_handle_t *)obj_handle;
  unsigned int cookie = argcookie ;

  /* sanity checks */
  if(!p_objecthandle || !p_context || !xattrs_tab || !p_nb_returned || !end_of_list)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_ListXAttrs);

  /* Deal with special cookie */
  if( argcookie == FSAL_XATTR_RW_COOKIE ) cookie = XATTR_COUNT ;

  /* object attributes we want to retrieve from parent */
  file_attrs.asked_attributes = FSAL_ATTR_MODE | FSAL_ATTR_FILEID | FSAL_ATTR_OWNER
      | FSAL_ATTR_GROUP | FSAL_ATTR_ATIME | FSAL_ATTR_MTIME | FSAL_ATTR_TYPE
      | FSAL_ATTR_CTIME | FSAL_ATTR_CREATION | FSAL_ATTR_CHGTIME | FSAL_ATTR_FSID;

  /* don't retrieve unsuipported attributes */
  file_attrs.asked_attributes &= global_fs_info.supported_attrs;

  st = ZFSFSAL_getattrs(obj_handle, p_context, &file_attrs);

  if(FSAL_IS_ERROR(st))
    Return(st.major, st.minor, INDEX_FSAL_ListXAttrs);

  /* Get the right VFS */
  ZFSFSAL_VFS_RDLock();
  libzfswrap_vfs_t *p_vfs = ZFSFSAL_GetVFS(p_objecthandle);
  if(!p_vfs)
  {
    ZFSFSAL_VFS_Unlock();
    Return(ERR_FSAL_NOENT, 0, INDEX_FSAL_ListXAttrs);
  }


  for(index = cookie, out_index = 0;
      index < XATTR_COUNT && out_index < xattrs_tabsize; index++)
    {
      if(do_match_type(xattr_list[index].flags, p_objecthandle->data.type))
        {
          /* fills an xattr entry */
          xattrs_tab[out_index].xattr_id = index;
          FSAL_str2name(xattr_list[index].xattr_name, FSAL_MAX_NAME_LEN,
                        &xattrs_tab[out_index].xattr_name);
          xattrs_tab[out_index].xattr_cookie = index + 1;

          /* set asked attributes (all supported) */
          xattrs_tab[out_index].attributes.asked_attributes =
              global_fs_info.supported_attrs;

          if(file_attributes_to_xattr_attrs
             (&file_attrs, &xattrs_tab[out_index].attributes, index))
            {
              /* set error flag */
              xattrs_tab[out_index].attributes.asked_attributes = FSAL_ATTR_RDATTR_ERR;
            }

          /* next output slot */
          out_index++;
        }
    }

  /* Save a call if the output array is full */
  if(out_index == xattrs_tabsize)
  {
    *end_of_list = FALSE;
    *p_nb_returned = out_index;
    ZFSFSAL_VFS_Unlock();
    Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_ListXAttrs);
  }

  /* List the extended attributes */
  char *psz_buffer;
  size_t i_size;

  cred.uid = p_context->credential.user;
  cred.gid = p_context->credential.group;

  TakeTokenFSCall();
  rc = libzfswrap_listxattr(p_vfs, &cred,
                            p_objecthandle->data.zfs_handle, &psz_buffer, &i_size);
  ReleaseTokenFSCall();
  ZFSFSAL_VFS_Unlock();

  if(rc)
    Return(posix2fsal_error(rc), 0, INDEX_FSAL_ListXAttrs);

  if(i_size > 0)
  {
    size_t len = 0;
    char *ptr;
    int xattr_idx;

    for(ptr = psz_buffer, xattr_idx = 0;
        (ptr < psz_buffer + i_size) && (out_index < xattrs_tabsize);
        xattr_idx++, ptr += len + 1)
    {
      len = strlen(ptr);
      index = XATTR_COUNT + xattr_idx;

      /* Skip if the index is before the cookie */
      if(index < cookie)
        continue;

      xattrs_tab[out_index].xattr_id = index;
      FSAL_str2name(ptr, len + 1, &xattrs_tab[out_index].xattr_name);
      xattrs_tab[out_index].xattr_cookie = index + 1;

      /* set asked attributes (all supported) */
      xattrs_tab[out_index].attributes.asked_attributes =
                                global_fs_info.supported_attrs;

      if(file_attributes_to_xattr_attrs(&file_attrs,
                                        &xattrs_tab[out_index].attributes,
                                        index))
      {
        /* set error flag */
        xattrs_tab[out_index].attributes.asked_attributes = FSAL_ATTR_RDATTR_ERR;
      }

      /* next output slot */
      out_index++;
    }

    /* Every xattrs are in the output array */
    if(ptr >= psz_buffer + i_size)
      *end_of_list = TRUE;
    else
      *end_of_list = FALSE;
  }
  else
    *end_of_list = TRUE;
  free(psz_buffer);

  *p_nb_returned = out_index;

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_ListXAttrs);

}
示例#27
0
/**
 * Retrieves the list of extended attributes for an object in the filesystem.
 * 
 * \param p_objecthandle Handle of the object we want to get extended attributes.
 * \param cookie index of the next entry to be returned.
 * \param p_context pointer to the current security context.
 * \param xattrs_tab a table for storing extended attributes list to.
 * \param xattrs_tabsize the maximum number of xattr entries that xattrs_tab
 *            can contain.
 * \param p_nb_returned the number of xattr entries actually stored in xattrs_tab.
 * \param end_of_list this boolean indicates that the end of xattrs list has been reached.
 */
fsal_status_t POSIXFSAL_ListXAttrs(fsal_handle_t * objecthandle, /* IN */
                                   unsigned int argcookie, /* IN */
                                   fsal_op_context_t * context,  /* IN */
                                   fsal_xattrent_t * xattrs_tab,        /* IN/OUT */
                                   unsigned int xattrs_tabsize, /* IN */
                                   unsigned int *p_nb_returned, /* OUT */
                                   int *end_of_list     /* OUT */
    )
{
  posixfsal_handle_t * p_objecthandle = (posixfsal_handle_t *) objecthandle;
  posixfsal_op_context_t * p_context = (posixfsal_op_context_t *) context;
  unsigned int index;
  unsigned int out_index;
  fsal_status_t st;
  fsal_attrib_list_t file_attrs;
  unsigned int cookie = argcookie ;

  /* sanity checks */
  if(!p_objecthandle || !p_context || !xattrs_tab || !p_nb_returned || !end_of_list)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_ListXAttrs);

  /* Deal with special cookie */
  if( argcookie == FSAL_XATTR_RW_COOKIE ) cookie = XATTR_COUNT ;

  /* object attributes we want to retrieve from parent */
  file_attrs.asked_attributes = FSAL_ATTR_MODE | FSAL_ATTR_FILEID | FSAL_ATTR_OWNER
      | FSAL_ATTR_GROUP | FSAL_ATTR_ATIME | FSAL_ATTR_MTIME
      | FSAL_ATTR_CTIME | FSAL_ATTR_CREATION | FSAL_ATTR_CHGTIME | FSAL_ATTR_FSID;

  /* don't retrieve unsuipported attributes */
  file_attrs.asked_attributes &= global_fs_info.supported_attrs;

  st = POSIXFSAL_getattrs(objecthandle, context, &file_attrs);

  if(FSAL_IS_ERROR(st))
    Return(st.major, st.minor, INDEX_FSAL_ListXAttrs);

  for(index = cookie, out_index = 0;
      index < XATTR_COUNT && out_index < xattrs_tabsize; index++)
    {
      if(do_match_type(xattr_list[index].flags, p_objecthandle->data.info.ftype))
        {
          /* fills an xattr entry */
          xattrs_tab[out_index].xattr_id = index;
          FSAL_str2name(xattr_list[index].xattr_name, FSAL_MAX_NAME_LEN,
                        &xattrs_tab[out_index].xattr_name);
          xattrs_tab[out_index].xattr_cookie = index + 1;

          /* set asked attributes (all supported) */
          xattrs_tab[out_index].attributes.asked_attributes =
              global_fs_info.supported_attrs;

          if(file_attributes_to_xattr_attrs
             (&file_attrs, &xattrs_tab[out_index].attributes, index))
            {
              /* set error flag */
              xattrs_tab[out_index].attributes.asked_attributes = FSAL_ATTR_RDATTR_ERR;
            }

          /* next output slot */
          out_index++;
        }
    }

  *p_nb_returned = out_index;
  *end_of_list = (index == XATTR_COUNT);

  Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_ListXAttrs);

}
示例#28
0
文件: fsal_xattrs.c 项目: ic-hep/emi3
/**
 * Retrieves the list of extended attributes for an object in the filesystem.
 * 
 * \param p_objecthandle Handle of the object we want to get extended attributes.
 * \param cookie index of the next entry to be returned.
 * \param p_context pointer to the current security context.
 * \param xattrs_tab a table for storing extended attributes list to.
 * \param xattrs_tabsize the maximum number of xattr entries that xattrs_tab
 *            can contain.
 * \param p_nb_returned the number of xattr entries actually stored in xattrs_tab.
 * \param end_of_list this boolean indicates that the end of xattrs list has been reached.
 */
fsal_status_t dpmfsal_ListXAttrs(fsal_handle_t * p_objecthandle, // IN
                                 unsigned int cookie, // IN
                                 fsal_op_context_t * p_context, // IN
                                 fsal_xattrent_t * xattrs_tab, // IN/OUT
                                 unsigned int xattrs_tabsize, // IN
                                 unsigned int *p_nb_returned, // OUT
                                 int *end_of_list // OUT
)
{
    unsigned int index;
    unsigned int out_index;
    fsal_status_t st;
    fsal_attrib_list_t file_attrs;

    LogInfo(COMPONENT_FSAL, "dpmfsal_ListXAttrs: start");

    /* sanity checks */
    if (!p_objecthandle || !p_context || !xattrs_tab || !p_nb_returned || !end_of_list)
        Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_ListXAttrs);

    /* object attributes we want to retrieve from parent */
    file_attrs.asked_attributes = FSAL_ATTR_MODE | FSAL_ATTR_FILEID
            | FSAL_ATTR_OWNER | FSAL_ATTR_GROUP | FSAL_ATTR_ATIME
            | FSAL_ATTR_MTIME | FSAL_ATTR_CTIME | FSAL_ATTR_CREATION
            | FSAL_ATTR_CHGTIME | FSAL_ATTR_FSID;

    /* don't retrieve unsupported attributes */
    file_attrs.asked_attributes &= global_fs_info.supported_attrs;

    st = FSAL_getattrs(p_objecthandle, p_context, &file_attrs);

    if (FSAL_IS_ERROR(st))
        Return(st.major, st.minor, INDEX_FSAL_ListXAttrs);

    for (index = cookie, out_index = 0; index < XATTR_COUNT && out_index
            < xattrs_tabsize; index++) {
        if (do_match_type(xattr_list[index].flags,
                p_objecthandle->data.ntype)) {
            /* fills an xattr entry */
            xattrs_tab[out_index].xattr_id = index;
            FSAL_str2name(xattr_list[index].xattr_name, FSAL_MAX_NAME_LEN,
                    &xattrs_tab[out_index].xattr_name);
            xattrs_tab[out_index].xattr_cookie = index + 1;

            /* set asked attributes (all supported) */
            xattrs_tab[out_index].attributes.asked_attributes
                    = global_fs_info.supported_attrs;

            if (file_attributes_to_xattr_attrs(&file_attrs,
                    &xattrs_tab[out_index].attributes, index)) {
                /* set error flag */
                xattrs_tab[out_index].attributes.asked_attributes
                        = FSAL_ATTR_RDATTR_ERR;
            }

            /* next output slot */
            out_index++;
        }
    }

    *p_nb_returned = out_index;
    *end_of_list = (index == XATTR_COUNT);

    Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_ListXAttrs);

}