Esempio n. 1
0
static int
HPSSFSAL_Common_Mkdir(apithrdstate_t * ThreadContext,
                      ns_ObjHandle_t * ObjHandle,
                      char *Path,
                      api_cwd_stack_t * CwdStack,
                      int Mode,
                      TYPE_CRED_HPSS * Ucred,
                      ns_ObjHandle_t * RetObjHandle, hpss_Attrs_t * RetAttrs)
{
#if HPSS_MAJOR_VERSION < 7
  call_type_t call_type;
#endif
#if HPSS_MAJOR_VERSION == 5
  volatile long error = 0;      /* return error */
#else
  signed32 error = 0;           /* return error */
#endif
  static char function_name[] = "HPSSFSAL_Common_Mkdir";
  ns_ObjHandle_t objhandle_parent;
  ns_ObjHandle_t objhandle_newdir;
  hpss_Attrs_t attr_parent;
  hpss_Attrs_t attr_newdir_in;
  hpss_Attrs_t attr_newdir_out;
  char *path_parent;
  char *path_newdir;
  retry_cb_t retry_cb;
  hpss_reqid_t rqstid;
  hpss_AttrBits_t select_flags;
  hpss_AttrBits_t update_flags;
  acct_rec_t new_acct_code;
  acct_rec_t temp_acct_code;
  TYPE_UUID_HPSS siteId;
  TYPE_TOKEN_HPSS ta;
#if defined ( API_DMAP_SUPPORT ) && !defined ( API_DMAP_GATEWAY )
  byte dm_handle[MAX_DMEPI_HANDLE_SIZE];
  unsigned32 dm_handle_length;
#endif

  API_ENTER(function_name);

  /*
   * Break the path into a path and a name, so that
   * we can get information about the parent.
   */

  path_parent = malloc(HPSS_MAX_PATH_NAME);
  if(path_parent == NULL)
    {
      return (-ENOMEM);
    }

  path_newdir = malloc(HPSS_MAX_PATH_NAME);
  if(path_newdir == NULL)
    {
      free(path_parent);
      return (-ENOMEM);
    }

  error = API_DivideFilePath(Path, path_parent, path_newdir);

  if(error != 0)
    {
      free(path_parent);
      free(path_newdir);
      return (error);
    }

  /*
   *  Get a valid request id.
   */

  rqstid = API_GetUniqueRequestID();

  /*
   * Get an object handle and ns attributes for the parent
   * directory in which the new directory is to be created.
   * Determine from the attributes of the parent directory
   * whether it is dmap managed or not, and from that determine
   * whether to call the dmap gateway or the name server to
   * create the new directory.
   */

  (void)memset(&attr_parent, 0, sizeof(attr_parent));
  (void)memset(&objhandle_parent, 0, sizeof(objhandle_parent));

  select_flags = API_AddRegisterValues(cast64m(0), CORE_ATTR_ACCOUNT,
#if HPSS_MAJOR_VERSION < 7
                                       CORE_ATTR_FILESET_ID,
                                       CORE_ATTR_FILESET_TYPE,
                                       CORE_ATTR_GATEWAY_UUID,
                                       CORE_ATTR_DM_HANDLE, CORE_ATTR_DM_HANDLE_LENGTH,
#endif
                                       -1);

  error = API_TraversePath(ThreadContext,
                           rqstid,
                           Ucred,
                           ObjHandle,
                           path_parent,
                           CwdStack,
                           API_CHASE_ALL,
                           0,
                           0,
                           select_flags,
                           cast64m(0),
                           API_NULL_CWD_STACK, &objhandle_parent, &attr_parent,
#if HPSS_MAJOR_VERSION < 7
                           NULL,
#endif
                           NULL, NULL, NULL, NULL);

  if(error != 0)
    {
      API_DEBUG_FPRINTF(DebugFile, &rqstid,
                        "%s: Could not get attributes.\n", function_name);
    }
  else
    {
      /*
       *  Check to see if we need to return the attributes of
       *  the newly created directory and set up the select flags
       *  appropriately.
       */

      if(RetAttrs != (hpss_Attrs_t *) NULL)
        {
          select_flags = API_AddAllRegisterValues(MAX_CORE_ATTR_INDEX);
        }
      else
        {
          select_flags = cast64m(0);
        }

      /*
       * Determine the appropriate accounting to use.
       */

      error = API_DetermineAcct(Ucred,
                                ThreadContext,
                                objhandle_parent.CoreServerUUID,
                                rqstid, &siteId, &temp_acct_code);
      if(error != 0)
        {
          API_DEBUG_FPRINTF(DebugFile, &rqstid,
                            "%s: Could not determine which"
                            " account to use.\n", function_name);
        }
      else
        {
          /*
           * Validate the account.
           */
#if HPSS_MAJOR_VERSION == 5
          error = av_cli_ValidateCreate(siteId,
                                        rqstid,
                                        Ucred->DCECellId,
                                        Ucred->SecPWent.Uid,
                                        Ucred->SecPWent.Gid,
                                        temp_acct_code,
                                        attr_parent.Account, &new_acct_code);
#elif (HPSS_MAJOR_VERSION == 6) || (HPSS_MAJOR_VERSION == 7)
          error = av_cli_ValidateCreate(siteId,
                                        rqstid,
                                        Ucred->RealmId,
                                        Ucred->Uid,
                                        Ucred->Gid,
                                        temp_acct_code,
                                        attr_parent.Account, &new_acct_code);
#endif

          if(error != 0)
            {
              API_DEBUG_FPRINTF(DebugFile, &rqstid,
                                "%s: Could not validate"
                                " the account.\n", function_name);
            }
        }
    }

  if(error == 0)
    {

#if HPSS_MAJOR_VERSION < 7

      /*
       * Do we call the dmap gateway or the name server?
       */

#if HPSS_MAJOR_VERSION == 5
      call_type = API_DetermineCall(attr_parent.FilesetType, (long *)&error);
#elif HPSS_MAJOR_VERSION == 6
      call_type = API_DetermineCall(attr_parent.FilesetType, &error);
#endif

      switch (call_type)
        {

        case API_CALL_DMG:

#if defined ( API_DMAP_SUPPORT ) && !defined ( API_DMAP_GATEWAY )
          /*
           * Call the dmap gateway to create the file.  This will
           * have the side effect that the dmap will call us to
           * create the directory on the hpss side.  By the time this
           * call returns, the directory will exist on both sides.
           */

          Ucred->CurAccount = new_acct_code;
          memset(dm_handle, 0, (sizeof(byte) * MAX_DMEPI_HANDLE_SIZE));
          memset(&dm_handle_length, 0, sizeof(unsigned32));

          /*
           * The mode should have the directory bit set and
           * the umask bits reset.
           */

          Mode |= S_IFDIR;
          Mode &= ~(ThreadContext->Umask);

          error = API_dmg_Create(ThreadContext, rqstid, Ucred, &attr_parent.GatewayUUID, attr_parent.FilesetId, attr_parent.DMHandle, attr_parent.DMHandleLength, path_newdir, Mode, NS_OBJECT_TYPE_DIRECTORY, NULL,    /* cos hints in */
                                 NULL,  /* cos hints priority */
                                 dm_handle, (unsigned32 *) & dm_handle_length, NULL);   /* cos hints out */

          if(error != 0)
            {
              API_DEBUG_FPRINTF(DebugFile, &rqstid,
                                "%s: API_dmg_Create failed.\n", function_name);
            }
          else
            {
              /*
               * If the caller asked for them, obtain the hpss attributes
               * and an object handle for the new directory.
               *
               * ChaseSymlinks and ChaseJunctions shouldn't matter at
               * this point; the object should be a directory.
               */

              if(RetObjHandle || RetVAttrs)
                {
                  error = API_TraversePath(ThreadContext,
                                           rqstid,
                                           Ucred,
                                           &objhandle_parent,
                                           path_newdir,
                                           CwdStack,
                                           API_CHASE_NONE,
                                           0,
                                           0,
                                           select_flags,
                                           cast64m(0),
                                           API_NULL_CWD_STACK,
                                           &objhandle_newdir,
                                           NULL,
                                           NULL, &attr_newdir_out, NULL, NULL, NULL);

                  if(error != 0)
                    {
                      API_DEBUG_FPRINTF(DebugFile, &rqstid,
                                        "%s: Could not get attributes"
                                        " of new directory.\n", function_name);
                    }
                }
            }
#else
          error = EACCES;
          API_DEBUG_FPRINTF(DebugFile, &rqstid,
                            "%s: No dmap support compiled in.\n", function_name);
#endif
          break;

        case API_CALL_HPSS:

#endif                          /* HPSS < 7 */

          /*
           * Set up the parameters for the new directory.
           */

          (void)memset(&attr_newdir_out, 0, sizeof(attr_newdir_out));
          (void)memset(&attr_newdir_in, 0, sizeof(attr_newdir_in));

          attr_newdir_in.Account = new_acct_code;

          API_ConvertPosixModeToMode(Mode & ~(ThreadContext->Umask), &attr_newdir_in);

          update_flags = API_AddRegisterValues(cast64m(0),
                                               CORE_ATTR_ACCOUNT,
                                               CORE_ATTR_USER_PERMS,
                                               CORE_ATTR_GROUP_PERMS,
                                               CORE_ATTR_OTHER_PERMS, -1);

#if defined(API_DMAP_GATEWAY)

          /*
           * If the gateway is trying to create a directory on a
           * mirrored fileset, it must supply a UID & GID for
           * the directory.
           */

          if(attr_parent.FilesetType == CORE_FS_TYPE_MIRRORED)
            {
              attr_newdir_in.UID = Ucred->SecPWent.Uid;
              attr_newdir_in.GID = Ucred->SecPWent.Gid;
              update_flags = API_AddRegisterValues(update_flags,
                                                   CORE_ATTR_UID, CORE_ATTR_GID, -1);
            }
#endif
          /*
           * Note: The DM handle is not loaded here for non
           * HPSS filesets because the handle can only be
           * determined after the file is created on the
           * DMAP side. Therefore, the gateway must update
           * the directories attributes after the directory
           * is created.
           */

          error = API_core_MkDir(ThreadContext,
                                 rqstid,
                                 Ucred,
                                 &objhandle_parent,
                                 path_newdir,
                                 update_flags,
                                 &attr_newdir_in,
                                 select_flags, &attr_newdir_out, &objhandle_newdir);

          if(error != 0)
            {
              API_DEBUG_FPRINTF(DebugFile, &rqstid,
                                "%s: Could not create directory"
                                ", error=%d\n", function_name, error);

              API_LogMsg(function_name, rqstid, CS_DEBUG,
                         SOFTWARE_ERROR, NONE, API_REQUEST_ERROR, error);
            }
#if HPSS_MAJOR_VERSION < 7
          break;

        default:
          if(error == 0)
            error = EIO;
          API_DEBUG_FPRINTF(DebugFile, &rqstid,
                            "%s: Bad case from DetermineCall().\n", function_name);
          break;
        }                       /* end switch */
#endif

    }

  /* end (if error == 0) */
  /*
   *  Convert the returned attributes, if necessary.
   */
  if(RetAttrs != (hpss_Attrs_t *) NULL)
    {
      *RetAttrs = attr_newdir_out;
    }

  if(RetObjHandle != (ns_ObjHandle_t *) NULL)
    *RetObjHandle = objhandle_newdir;

  free(path_newdir);
  free(path_parent);

  return (error);
}
Esempio n. 2
0
static int
HPSSFSAL_Common_ReadAttrs(apithrdstate_t * ThreadContext,
                          sec_cred_t * UserCred,
                          ns_ObjHandle_t * ObjHandle,
                          unsigned32 ChaseOptions,
                          u_signed64 OffsetIn,
                          unsigned32 BufferSize,
                          unsigned32 GetAttributes,
                          unsigned32 IgnInconstitMd,
                          unsigned32 * End,
                          u_signed64 * OffsetOut, ns_DirEntry_t * DirentPtr)
{
  int cnt;
  ns_DirEntryConfArray_t direntbuf;
  ns_DirEntry_t *direntptr;
  long error = 0;
  char function_name[] = "HPSSFSAL_Common_ReadAttrs";
  unsigned32 i;
#if HPSS_LEVEL >= 622
  unsigned32 entry_cnt;
#endif
  ns_DirEntry_t *outptr;
  hpss_reqid_t rqstid;
  u_signed64 select_flags;

#if HPSS_LEVEL >= 622
  /* figure out how many entries will fit in the clients buffer */
  entry_cnt = BufferSize / sizeof(ns_DirEntry_t);
#endif

  direntbuf.DirEntry.DirEntry_len = 0;
  direntbuf.DirEntry.DirEntry_val = NULL;

  if(GetAttributes == TRUE)
    {
      /*
       * Ask for all the attributes that are managed by the
       * Name Service. Start by setting all the bits in
       * the select flags, then clear the ones that are specific
       * to the Bitfile Service.
       */

      select_flags = API_AddAllRegisterValues(MAX_CORE_ATTR_INDEX);
      select_flags = API_RemoveRegisterValues(select_flags,
#if HPSS_MAJOR_VERSION < 7
                                              CORE_ATTR_DM_DATA_STATE_FLAGS,
                                              CORE_ATTR_DONT_PURGE,
#endif
                                              CORE_ATTR_REGISTER_BITMAP,
                                              CORE_ATTR_OPEN_COUNT,
                                              CORE_ATTR_READ_COUNT,
                                              CORE_ATTR_WRITE_COUNT,
                                              CORE_ATTR_TIME_LAST_WRITTEN, -1);
    }
  else
    select_flags = cast64m(0);

  /*
   *  Get a valid request Id and then read the directory entries.
   */

  rqstid = API_GetUniqueRequestID();

  error = API_core_ReadDir(ThreadContext,
                           rqstid,
                           UserCred,
                           ObjHandle,
                           OffsetIn, BufferSize, select_flags, End, &direntbuf);

  /* In case of metadata inconsistency, it may return HPSS_ENOENT 
   * when a directory entry has no associated entry in the FS...
   * In this case, we return null object attributes.
   */
  if((error == HPSS_ENOENT) && IgnInconstitMd)
    {
      select_flags = cast64m(0);

      rqstid = API_GetUniqueRequestID();

      error = API_core_ReadDir(ThreadContext,
                               rqstid,
                               UserCred,
                               ObjHandle,
                               OffsetIn, BufferSize, select_flags, End, &direntbuf);
    }

  if(error != 0)
    {
      API_DEBUG_FPRINTF(DebugFile, &rqstid,
                        "%s: Could not read directory entries.\n", function_name);
    }

  if(error == 0)
    {

      /*
       *  Now load in the results from the call.
       */

      (void)memset(DirentPtr, 0, BufferSize); /* Todo Why does this crash the daemon ??*/
      cnt = 0;

#if HPSS_LEVEL >= 622
      for(i = 0; i < direntbuf.DirEntry.DirEntry_len && i < entry_cnt; ++i)
#else
      for(i = 0; i < direntbuf.DirEntry.DirEntry_len; ++i)
#endif
        {
          direntptr = &(direntbuf.DirEntry.DirEntry_val[i]);
          outptr = &DirentPtr[cnt++];

          /*
           * If asked to chase junctions and this entry
           * is a junction, return the attributes for
           * the fileset/directory to which the junction
           * points.
           */

          if(((ChaseOptions & API_CHASE_JUNCTION) != 0)
             && direntptr->Attrs.Type == NS_OBJECT_TYPE_JUNCTION)
            {
              hpss_Attrs_t attrs;
              ns_ObjHandle_t obj_handle;
              u_signed64 select_flags;

              memset(&obj_handle, 0, sizeof(obj_handle));
              memset(&attrs, 0, sizeof(attrs));
              select_flags = API_AddAllRegisterValues(MAX_CORE_ATTR_INDEX);

              error = API_TraversePath(ThreadContext,
                                       rqstid,
                                       &ThreadContext->UserCred,
                                       ObjHandle,
                                       (char *)direntptr->Name,
                                       API_NULL_CWD_STACK,
                                       API_CHASE_JUNCTION,
                                       0,
                                       0,
                                       select_flags,
                                       cast64m(0),
                                       API_NULL_CWD_STACK,
                                       &obj_handle, &attrs, NULL, NULL,
#if HPSS_MAJOR_VERSION < 7
                                       NULL,
#endif
                                       NULL, NULL);

              if(error != 0)
                {
                  /*
                   * If we can't find out what the junction points
                   * to, log a message and return the attributes
                   * of the junction itself.
                   */

                  API_DEBUG_FPRINTF(DebugFile, &rqstid,
                                    "HPSSFSAL_Common_ReadAttrs: API_TraversePath"
                                    "failed, error = %d\n", error);
                  error = 0;
                }
              else
                {
                  /*
                   * We got the fileset attributes, copy
                   * them to the entry.
                   */

                  direntptr->ObjHandle = obj_handle;
                  direntptr->Attrs = attrs;
                }
            }

          *outptr = *direntptr;

        }

      if(error == 0)
        {
          if(direntbuf.DirEntry.DirEntry_len > 0)
            *OffsetOut = outptr->ObjOffset;
          else
            *OffsetOut = cast64m(0);

          /*
           *  Return the number of entries returned from the
           *  core server.
           */

          error = cnt;
        }
    }

  if(direntbuf.DirEntry.DirEntry_val != NULL)
    {
      free(direntbuf.DirEntry.DirEntry_val);
    }

  return (error);
}
Esempio n. 3
0
int
main (int argc, char *argv[])
{
  int i, fd, hfd, rc, len;
  double start, elapsed, double_time ();
  char *buf;
  u_signed64 size64, count64;
  hpss_fileattr_t attr;
  char c;

  while ((c = getopt (argc, argv, COMMON_OPTS)) != -1)
    {
      switch (c)
	{
	case 'h':
	case '?':
	  usage ();
	  exit (0);
	default:
	  if (scan_cmdline_authargs (c, optarg))
	    {
	      usage ();
	      exit (1);
	    }
	}
    }

  if (optind == argc)
    {
      usage ();
      exit (1);
    }


  /* allocate the data buffer */
  buf = (char *) malloc (BUFSIZE);
  if (buf == NULL)
    {
      fprintf (stderr, "%s: could not allocate memory\n", argv[0]);
      exit (0);
    }

  authenticate ();

  for (i = optind; i < argc; i++)
    {
      /* open the source file */
      hfd = hpss_Open (argv[i], O_RDONLY, 0, NULL, NULL, NULL);
      if (hfd < 0)
	{
	  fprintf (stderr, "hpss_Open: ");
	  perror (argv[i]);
	  hpss_exit (1);
	}

      /* get the length of the source file */
      if (hpss_FileGetAttributes (argv[i], &attr) < 0)
	{
	  fprintf (stderr, "hpss_FileGetAttributes: ");
	  perror (argv[i]);
	  hpss_exit (1);
	}
      size64 = attr.Attrs.DataLength;

      /* loop through the source files */
      count64 = cast64m (0);
      {

	/* read in the next chunk of data */
	len = hpss_Read (hfd, buf, BUFSIZE);
	if (len <= 0)
	  {
	    perror ("hpss_Read");
	    hpss_exit (1);
	  }
      }
      hpss_Close (hfd);
    }

  hpss_exit (0);
}