Example #1
0
static int hpss_get_file_slevel(struct fsal_obj_handle *fsal_obj_hdl,
				caddr_t buffer_addr,
				size_t buffer_size,
				size_t *p_output_size,
				void *arg)
{
	struct hpss_fsal_obj_handle *obj_hdl;
	sec_cred_t *p_ucreds = arg;
	hpss_xfileattr_t hpss_xattr;
	char tmpstr[1024];
	char *outbuff;
	int rc, i, j;

	/* sanity checks. */
	if (!fsal_obj_hdl || !p_output_size || !buffer_addr || !p_ucreds)
		return ERR_FSAL_FAULT;


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


	rc = hpss_FileGetXAttributesHandle(&(obj_hdl->handle->ns_handle),
					   NULL,
					   p_ucreds,
					   API_GET_STATS_FOR_ALL_LEVELS,
					   0,
					   &hpss_xattr);

	if (rc == HPSS_ENOENT)
		return ERR_FSAL_STALE;

	if (rc)
		return hpss2fsal_error(rc);

	/* now write info to buffer */
	outbuff = (char *)buffer_addr;
	outbuff[0] = '\0';

	for (i = 0; i < HPSS_MAX_STORAGE_LEVELS; i++) {
		if (hpss_xattr.SCAttrib[i].Flags == 0)
			continue;

		if (hpss_xattr.SCAttrib[i].Flags & BFS_BFATTRS_LEVEL_IS_DISK)
			snprintf(tmpstr, 1024,
				 "Level %u (disk): %"PRIu64" bytes\n", i,
				 hpss2fsal_64(hpss_xattr.SCAttrib[i].
						BytesAtLevel));
		else
			if (hpss_xattr.SCAttrib[i].Flags &
				 BFS_BFATTRS_LEVEL_IS_TAPE)
				snprintf(tmpstr, 1024,
					 "Level %u (tape): %"PRIu64" bytes\n",
					 i,
					 hpss2fsal_64(hpss_xattr.SCAttrib[i].
						BytesAtLevel));
			else
				snprintf(tmpstr, 1024,
					 "Level %u: %"PRIu64" bytes\n", i,
					 hpss2fsal_64(hpss_xattr.SCAttrib[i].
						BytesAtLevel));

		if (strlen(tmpstr) + strlen(outbuff) < buffer_size)
			strcat(outbuff, tmpstr);
		else
			break;
	 }

	/* free the returned structure (Cf. HPSS ClAPI documentation) */
	for (i = 0; i < HPSS_MAX_STORAGE_LEVELS; i++)
		for (j = 0; j < hpss_xattr.SCAttrib[i].NumberOfVVs; j++)
			if (hpss_xattr.SCAttrib[i].VVAttrib[j].PVList != NULL)
				free(hpss_xattr.SCAttrib[i].VVAttrib[j].
						PVList);

	*p_output_size = strlen(outbuff);

	return 0;
}
Example #2
0
/**
 * hpss2fsal_attributes:
 * Fills an FSAL attributes structure with the info
 * provided by the hpss handle and the hpss attributes
 * of an object.
 *
 * \param p_hpss_handle_in (input):
 *        Pointer to the HPSS NS object handle.
 * \param p_hpss_attr_in (input):
 *        Pointer to the HPSS attributes.
 * \param p_fsalattr_out (input/output):
 *        Pointer to the FSAL attributes.
 *        As input, it defines the attributes that the caller
 *        wants to retrieve (by positioning flags into this structure)
 *        and the output is built considering this input
 *        (it fills the structure according to the flags it contains).
 * \param p_cred (input)
 *        HPSS Credential.
 *
 * \return Major error codes:
 *      - ERR_FSAL_NO_ERROR: no error.
 *      - ERR_FSAL_FAULT: NULL pointer passed as input parameter.
 *      - ERR_FSAL_ATTRNOTSUPP: One of the asked attributes is not supported.
 *      - ERR_FSAL_SERVERFAULT: Unexpected error.
 */
fsal_status_t hpss2fsal_attributes(ns_ObjHandle_t * p_hpss_handle_in,
                                   hpss_Attrs_t * p_hpss_attr_in,
                                   fsal_attrib_list_t * p_fsalattr_out)
{

  fsal_attrib_mask_t supp_attr, unsupp_attr;

  /* sanity checks */
  if(!p_hpss_handle_in || !p_hpss_attr_in || !p_fsalattr_out)
    ReturnCode(ERR_FSAL_FAULT, 0);

  if(p_fsalattr_out->asked_attributes == 0)
    {
      p_fsalattr_out->asked_attributes = global_fs_info.supported_attrs;

      LogCrit(COMPONENT_FSAL,
          "Error: p_fsalattr_out->asked_attributes  valait 0 dans hpss2fsal_attributes line %d, fichier %s",
           __LINE__, __FILE__);
    }

  /* check that asked attributes are supported */
  supp_attr = global_fs_info.supported_attrs;

  unsupp_attr = (p_fsalattr_out->asked_attributes) & (~supp_attr);

  if(unsupp_attr)
    {
      LogFullDebug(COMPONENT_FSAL,
                        "Unsupported attributes: %#llX    removing it from asked attributes ",
                        unsupp_attr);

      p_fsalattr_out->asked_attributes =
          p_fsalattr_out->asked_attributes & (~unsupp_attr);

      /* ReturnCode( ERR_FSAL_ATTRNOTSUPP, 0 ); */
    }

  /* Initialize ACL regardless of whether ACL was asked or not.
   * This is needed to make sure ACL attribute is initialized. */
  p_fsalattr_out->acl = NULL;

  /* Fills the output struct */
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SUPPATTR))
    {
      p_fsalattr_out->supported_attributes = supp_attr;
    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_TYPE))
    {
      p_fsalattr_out->type = hpss2fsal_type(p_hpss_handle_in->Type);
    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SIZE))
    {
      p_fsalattr_out->filesize = hpss2fsal_64(p_hpss_attr_in->DataLength);
    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_FSID))
    {
      p_fsalattr_out->fsid = hpss2fsal_fsid(p_hpss_attr_in->FilesetId);
    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_ACL))
    {

      if(p_hpss_attr_in->ExtendedACLs == 0)
        {
          p_fsalattr_out->acl = NULL;
        }
      else
        {

      /** @todo : This doesn't convert ACLs for the moment. */

        }

    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_FILEID))
    {
      p_fsalattr_out->fileid = (fsal_u64_t) hpss_GetObjId(p_hpss_handle_in);
    }

  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MODE))
    {
      p_fsalattr_out->mode = hpss2fsal_mode(
#if HPSS_MAJOR_VERSION < 7
                                             p_hpss_attr_in->SetUIDBit,
                                             p_hpss_attr_in->SetGIDBit,
                                             p_hpss_attr_in->SetStickyBit,
#else
                                             p_hpss_attr_in->ModePerms & NS_PERMS_RD,
                                             p_hpss_attr_in->ModePerms & NS_PERMS_WR,
                                             p_hpss_attr_in->ModePerms & NS_PERMS_XS,
#endif
                                             p_hpss_attr_in->UserPerms,
                                             p_hpss_attr_in->GroupPerms,
                                             p_hpss_attr_in->OtherPerms);
    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_NUMLINKS))
    {
      p_fsalattr_out->numlinks = p_hpss_attr_in->LinkCount;
    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_OWNER))
    {
      p_fsalattr_out->owner = p_hpss_attr_in->UID;
    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_GROUP))
    {
      p_fsalattr_out->group = p_hpss_attr_in->GID;
    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_ATIME))
    {

      LogFullDebug(COMPONENT_FSAL, "Getting ATIME:");
      LogFullDebug(COMPONENT_FSAL, "\tTimeLastRead = %d",
                        p_hpss_attr_in->TimeLastRead);
      LogFullDebug(COMPONENT_FSAL, "\tTimeCreated = %d",
                        p_hpss_attr_in->TimeCreated);

      if(p_hpss_attr_in->TimeLastRead != 0)
        p_fsalattr_out->atime = hpss2fsal_time(p_hpss_attr_in->TimeLastRead);
      else
        p_fsalattr_out->atime = hpss2fsal_time(p_hpss_attr_in->TimeCreated);

    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CREATION))
    {
      p_fsalattr_out->creation = hpss2fsal_time(p_hpss_attr_in->TimeCreated);
    }

  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CTIME))
    {
      p_fsalattr_out->ctime = hpss2fsal_time(p_hpss_attr_in->TimeModified);
    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MTIME))
    {

      LogFullDebug(COMPONENT_FSAL, "Getting MTIME:");
      LogFullDebug(COMPONENT_FSAL, "\tType = %d",
                        hpss2fsal_type(p_hpss_handle_in->Type));
      LogFullDebug(COMPONENT_FSAL, "\tTimeLastWritten = %d",
                        p_hpss_attr_in->TimeLastWritten);
      LogFullDebug(COMPONENT_FSAL, "\tTimeModified = %d",
                        p_hpss_attr_in->TimeModified);
      LogFullDebug(COMPONENT_FSAL, "\tTimeCreated = %d",
                        p_hpss_attr_in->TimeCreated);

      switch (hpss2fsal_type(p_hpss_handle_in->Type))
        {

        case FSAL_TYPE_FILE:
        case FSAL_TYPE_LNK:

          if(p_hpss_attr_in->TimeLastWritten != 0)
            p_fsalattr_out->mtime = hpss2fsal_time(p_hpss_attr_in->TimeLastWritten);
          else
            p_fsalattr_out->mtime = hpss2fsal_time(p_hpss_attr_in->TimeCreated);
          break;

        case FSAL_TYPE_DIR:
        case FSAL_TYPE_JUNCTION:

          if(p_hpss_attr_in->TimeModified != 0)
            p_fsalattr_out->mtime = hpss2fsal_time(p_hpss_attr_in->TimeModified);
          else
            p_fsalattr_out->mtime = hpss2fsal_time(p_hpss_attr_in->TimeCreated);
          break;

        default:
          ReturnCode(ERR_FSAL_SERVERFAULT, 0);

        }
    }

  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_CHGTIME))
    {
      p_fsalattr_out->chgtime
          =
          hpss2fsal_time(MAX_3
                         (p_hpss_attr_in->TimeModified, p_hpss_attr_in->TimeCreated,
                          p_hpss_attr_in->TimeLastWritten));
      p_fsalattr_out->change = (uint64_t) p_fsalattr_out->chgtime.seconds ;
    }

  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_SPACEUSED))
    {
      p_fsalattr_out->spaceused = hpss2fsal_64(p_hpss_attr_in->DataLength);
    }
  if(FSAL_TEST_MASK(p_fsalattr_out->asked_attributes, FSAL_ATTR_MOUNTFILEID))
    {
      p_fsalattr_out->mounted_on_fileid = hpss2fsal_64(p_hpss_attr_in->FilesetRootId);
    }

  /* everything has been copied ! */

  ReturnCode(ERR_FSAL_NO_ERROR, 0);

}