示例#1
0
/**
 * Build .lustre/fid path associated to a handle.
 */
int BuildFidPath( const entry_id_t * p_id,       /* IN */
                  char *path )                   /* OUT */
{
    char          *curr = path;
    unsigned int  mlen = 0;

    if ( !p_id || !path )
        return EFAULT;

    /* filesystem root */
    strcpy( path, get_mount_point(&mlen) );
    curr += mlen;

    /* fid directory */
    strcpy( curr, "/" FIDDIR "/" );
    curr += FIDDIRLEN + 2;

    /* add fid string */
    curr += sprintf( curr, DFID, PFID(p_id) );

#ifdef _DEBUG
    DisplayLog( LVL_FULL, TAG_FIDPATH, "FidPath=%s", path );
#endif

    return 0;
}
示例#2
0
/** Trigger a HSM action */
int LustreHSM_Action( enum hsm_user_action action, const entry_id_t * p_id,
                      const char * hints, unsigned int archive_id )
{
    struct hsm_user_request * req;
    int data_len = 0;
    int rc;
    char * mpath;

    if ( hints != NULL )
        data_len = strlen(hints)+1;

    req = llapi_hsm_user_request_alloc(1, data_len);

    if (!req)
    {
        rc = -errno;
        DisplayLog( LVL_CRIT, "HSMAction", "Cannot create HSM request: %s",
            strerror(-rc) );
        return rc;
    }

    req->hur_request.hr_action = action;
    req->hur_request.hr_archive_id = archive_id;

    req->hur_user_item[0].hui_fid = *p_id;
    req->hur_user_item[0].hui_extent.offset = 0 ;
    /* XXX for now, always transfer entire file */
    req->hur_user_item[0].hui_extent.length = -1LL;

    req->hur_request.hr_itemcount = 1;

    if ( hints != NULL )
    {
        req->hur_request.hr_data_len = data_len;
        memcpy(hur_data(req), hints, data_len);
    }
    else
    {
        req->hur_request.hr_data_len = 0;
    }

    /* make tmp copy as llapi_hsm_request arg is not const */
    mpath = strdup(get_mount_point(NULL));
    rc = llapi_hsm_request(mpath, req);
    free(mpath);
    free(req);

    if (rc)
        DisplayLog( LVL_CRIT, "HSMAction", "ERROR performing HSM request(%s,"
                    " root=%s, fid="DFID"): %s",
                    hsm_user_action2name(action), mpath, PFID(p_id),
                    strerror(-rc) );
    return rc;

}
示例#3
0
文件: arsenal.c 项目: jdegges/arsenal
int
main (int argc, char **argv)
{
  int ret;
  struct fuse_args args = FUSE_ARGS_INIT (argc, argv);

  get_mount_point (argc, argv);
  memset (&options, 0, sizeof (struct options));
  if (-1 == fuse_opt_parse (&args, &options, arsenal_opts, NULL))
    return -1;
  ret = fuse_main (args.argc, args.argv, &arsenal_oper, NULL);
  fuse_opt_free_args (&args);
  return ret;
}
示例#4
0
/* Get POSIX path from fid (fid2path wrapper) */
int Lustre_GetFullPath( const entry_id_t * p_id, char *fullpath, unsigned int len )
{
    char          *curr = fullpath;
    int            rc;
    long long      recno = -1;
    int            linkno = 0;
    char           fid[256];
    const char    *mpath = NULL;
    unsigned int   mlen = 0;

    mpath = get_mount_point(&mlen);

    /* set mountpoint at the beginning of the path */
    strcpy( fullpath, mpath );
    curr += mlen;

/* add the slash only if fid2path doesn't */
#ifndef _FID2PATH_LEADING_SLASH
    /* add slash */
    *curr = '/';
    curr ++;
#endif
    /* just in case fid2path returns nothing */
    *curr = '\0';

    /* fid string */
    sprintf( fid, DFID, PFID(p_id) );

    /* MDT device */

    /* ask the path to lustre */
    rc = llapi_fid2path( mpath, fid, curr, len - mlen - 2, &recno,
                         &linkno );

    if ( (rc != 0) && (rc != -ENOENT) && (rc != -ESTALE) )
        DisplayLog( LVL_CRIT, "Fid2Path",
                    "Error %d calling llapi_fid2path(%s,%s,%lld,%d), errno=%d."
                    " Cannot retrieve full path for %s",
                    rc, mpath, fid, recno, linkno, errno, fid );
    /* curr == fullpath => fullpath is root: '/'
     * so don't remove final slash */
    else if (curr != fullpath)
    {
        while (FINAL_SLASH(fullpath))
            REMOVE_FINAL_SLASH(fullpath);
    }

    return rc;
}
示例#5
0
void action_w(char *optarg)
{		
	char device_name[50], *mountpoint, mountpointpath[50], mountpointname[200], *filename=NULL;
	int lastslashpos, toumount=NO;
	
	if (optarg==NULL)
	{
	    strcpy(device_name, "/dev/sr0");
	}
	else
	{
	    strcpy(device_name, optarg);
	}
	
	mountpoint=get_mount_point(device_name);
	
	fprintf(stderr, "%s", mountpoint);
	if (*mountpoint=='\0')
	{
	    mountpoint=create_mount_point(device_name);
	    toumount=YES;
	}
	
	filename = get_cd_label(device_name);
	
	create_file(filename);
	
	lastslashpos=getlastcharpos(mountpoint, '/');
	
	#ifdef Daction_w
	//fprintf(stderr, "%d", lastslashpos);
	#endif
	
	strncpy(mountpointpath, mountpoint, lastslashpos+1);
	strcpy(mountpointname, mountpoint+lastslashpos+1);
	#ifdef DEBUG
	fprintf(stderr, "\n%s %s %s\n", __func__, mountpointpath, mountpointname); 
	#endif
	write_structure(mountpointpath, mountpointname, filename);
	if (toumount==YES)
	{
	    unmount_device(mountpoint);
	}
	add_master_file(get_cd_label(device_name), filename);
}
示例#6
0
int Path2Id(const char *path, entry_id_t *id)
{
    int rc;
    unsigned int len;
    char rpath[RBH_PATH_MAX];
    const char *mnt;
    char *tmp_path;

    mnt = get_mount_point(&len);
    tmp_path = realpath(path, NULL);

    if (tmp_path == NULL) {
        rc = -errno;
        DisplayLog(LVL_CRIT, P2ID_TAG, "Error in realpath(%s): %s",
                   path, strerror(-rc));
        return rc;
    }
    if (strlen(tmp_path) >= RBH_PATH_MAX) {
        free(tmp_path);
        DisplayLog(LVL_CRIT, P2ID_TAG, "Path length is too long!");
        return -ENAMETOOLONG;
    }
    /* safe because of previous check */
    strcpy(rpath, tmp_path);
    /* now can release tmp path */
    free(tmp_path);

    /* check that path is under FS root */
    if (strncmp(mnt, rpath, len)) {
        /* if path differs from realpath, display both */
        if (strcmp(path, rpath))
            DisplayLog(LVL_CRIT, P2ID_TAG,
                       "Error: %s (%s) is not under filesystem root %s", path,
                       rpath, mnt);
        else
            DisplayLog(LVL_CRIT, P2ID_TAG,
                       "Error: %s is not under filesystem root %s", path, mnt);
        return -EINVAL;
    }

    rc = path2id(path, id, NULL);
    return rc;
}
示例#7
0
int lustre_mds_stat_by_fid( const entry_id_t * p_id, struct stat *inode )
{
    char filename[MAXNAMLEN];
    char           buffer[1024];
    struct lov_user_mds_data *lmd = ( struct lov_user_mds_data * ) buffer;
    int rc;

    /* ensure fid directory is opened */
    if ( fid_dir_fd == NULL )
    {
        P( dir_lock );
        if ( fid_dir_fd == NULL )
        {
            char path[RBH_PATH_MAX];
            char *curr = path;
            unsigned int mlen;

            /* filesystem root */
            strcpy( path, get_mount_point(&mlen) );
            curr += mlen;

            /* fid directory */
            strcpy( curr, "/" FIDDIR );

            /* open fir directory */
            fid_dir_fd = opendir( path );
        }
        V( dir_lock );
        if ( fid_dir_fd == NULL )
            return errno;
    }

    sprintf( filename, DFID, PFID(p_id) );
    memset( lmd, 0, sizeof( buffer ) );
    rh_strncpy(buffer, filename, strlen(filename) + 1);

    rc = ioctl( dirfd( fid_dir_fd ), IOC_MDC_GETFILEINFO, ( void * ) lmd );

    if ( rc )
    {
        if ( errno == ENOTTY )
        {
            return ENOTSUP;
        }
        else if ( ( errno == ENOENT ) || ( errno == ESTALE ) )
        {
            DisplayLog( LVL_MAJOR, TAG_MDSSTAT, "Warning: %s: %s does not exist",
                        __FUNCTION__, filename );
            return ENOENT;
        }
        else
        {
            DisplayLog( LVL_CRIT, TAG_MDSSTAT,
                        "Error: %s: IOC_MDC_GETFILEINFO failed for %s",
                        __FUNCTION__, filename );
            return errno;
        }
    }

    *inode = lmd->lmd_st;
    return 0;
}
示例#8
0
/** Retrieve pool usage info
 *  @return 0 on success
 */
int Get_pool_usage( const char *poolname, struct statfs *pool_statfs )
{
    struct statfs  ost_statfs;
    int            rc, i, count;
    char           pool[LOV_MAXPOOLNAME + 10];
#ifdef FIND_MAX_OSTS
    char          *ostlist[FIND_MAX_OSTS];
    char           buffer[4096];
#else /* no max OST count since Lustre 2.2 */
    unsigned int obdcount = 256;
    char        **ostlist = NULL;
    int          bufsize = sizeof(struct obd_uuid) * obdcount;
    char *buffer = MemAlloc(bufsize + (sizeof(*ostlist) * obdcount));
    ostlist = (char **)(buffer + bufsize);

    /* sanity check */
    if (!pool_statfs)
    {
        MemFree(buffer);
        return EFAULT;
    }
#endif

    memset( pool_statfs, 0, sizeof( struct statfs ) );

    /* retrieve list of OSTs in the pool */
    sprintf( pool, "%s.%s", get_fsname(), poolname );
#ifdef FIND_MAX_OSTS
    rc = llapi_get_poolmembers(pool, ostlist, FIND_MAX_OSTS, buffer, 4096);
#else
    do {
        rc = llapi_get_poolmembers(pool, ostlist, obdcount, buffer, bufsize);
        if (rc == -EOVERFLOW)
        {
            /* buffer too small, increase obdcount by 2 */
            obdcount *= 2;
            bufsize = sizeof(struct obd_uuid) * obdcount;
            buffer = MemRealloc(buffer, bufsize + (sizeof(*ostlist) * obdcount));
            if (buffer == NULL)
                return ENOMEM;
            ostlist = (char **)(buffer + bufsize);
        }
    } while (rc == -EOVERFLOW);
#endif

    if ( rc < 0 )
        return -rc;

    count = rc;

    /* get OST info and sum them */
    for ( i = 0; i < count; i++ )
    {
        char          *ost;
        int            index;
        /* get ost index in <fsname>-OST<index>_UUID */
        ost = strrchr( ostlist[i], '-' );
        if ( !ost )
        {
            DisplayLog( LVL_CRIT, TAG_POOLDF, "Invalid OST format: '%s'", ostlist[i] );
            return EINVAL;
        }

        /* skip '-' */
        ost++;
        if ( sscanf( ost, "OST%d", &index ) != 1 )
        {
            DisplayLog( LVL_CRIT, TAG_POOLDF, "Could not find OST index in"
                        " string '%s'", ost );
            return EINVAL;
        }

        rc = Get_OST_usage( get_mount_point(NULL), index, &ost_statfs );
        if ( rc )
            return rc;

        /* sum info to struct statfs */
        pool_statfs->f_blocks += ost_statfs.f_blocks;
        pool_statfs->f_bfree += ost_statfs.f_bfree;
        pool_statfs->f_bavail += ost_statfs.f_bavail;
        pool_statfs->f_bsize = ost_statfs.f_bsize;
    }

    return 0;
}
示例#9
0
int
dobackmnt(struct cachefs_mountargs *margsp, char *reducep, char *specp,
    char *backfstypep, char *mynamep, int readonly)
{
	int xx;
	pid_t pid;
	char *newargv[20];
	int stat_loc;

	/* get a suitable mount point */
	xx = get_mount_point(margsp->cfs_cachedir, specp, &margsp->cfs_backfs);
	if (xx)
		return (1);

	/* construct argument list for mounting the back file system */
	xx = 1;
	newargv[xx++] = "mount";
	if (readonly)
		newargv[xx++] = "-r";
	if (nomnttab)
		newargv[xx++] = "-m";
	if (quiet)
		newargv[xx++] = "-q";
	if (reducep) {
		newargv[xx++] = "-o";
		newargv[xx++] = reducep;
	}
	newargv[xx++] = specp;
	newargv[xx++] = margsp->cfs_backfs;
	newargv[xx++] = NULL;

	/* fork */
	if ((pid = fork()) == -1) {
		pr_err(gettext("could not fork %s"), strerror(errno));
		return (1);
	}

	/* if the child */
	if (pid == 0) {
		/* do the mount */
		doexec(backfstypep, newargv, mynamep);
	}

	/* else if the parent */
	else {
		/* wait for the child to exit */
		if (wait(&stat_loc) == -1) {
			pr_err(gettext("wait failed %s"), strerror(errno));
			return (1);
		}

		if (!WIFEXITED(stat_loc)) {
			pr_err(gettext("back mount did not exit"));
			return (1);
		}

		xx = WEXITSTATUS(stat_loc);
		if (xx) {
			pr_err(gettext("back mount failed"));
			return (xx);
		}
	}

	return (0);
}
示例#10
0
文件: uhvm.c 项目: mjessome/uhvm
/* Callback function, called when a new device has been inserted. */
static void
device_added(LibHalContext *context, const char *did)
{
    const char *dudi, *fstype;
    char *dev, *mountp, *mountable, *label, *locked_reason;
    LibHalVolume *volume;
    LibHalDrive *drive;
    struct device_t *device;

    if (libhal_device_property_exists(context, did, "info.locked",
                                      (DBusError *)NULL)
            && libhal_device_get_property_bool(context, did, "info.locked",
                                               (DBusError *)NULL)) {
        if (debug_mode_flag) {
            locked_reason = libhal_device_get_property_string(
                                context, did, "info.locked.reason",
                                (DBusError *)NULL);
            if (locked_reason) {
                if (debug_mode_flag)
                    printf("%s%d: %s\n", __FILE__, __LINE__, locked_reason);
                libhal_free_string(locked_reason);
            }
        }
        return;
    }

    if (!libhal_device_query_capability(context, did, "volume",
                                        (DBusError *)NULL))
        return;
    label = libhal_device_get_property_string(context, did, "volume.label",
                                              (DBusError *)NULL);
    if (!(mountable = libhal_device_get_property_string(
                          context, did, "volume.fsusage", (DBusError *)NULL))
            || strcmp(mountable, "filesystem"))
        goto out;
    if (!(volume = libhal_volume_from_udi(context, did)))
        goto out;
    if (!(dudi = libhal_volume_get_storage_device_udi(volume)))
        goto out;
    if (!(drive = libhal_drive_from_udi(context, dudi)))
        goto out;
    if (!libhal_drive_is_hotpluggable(drive)
            && !libhal_drive_uses_removable_media(drive))
        goto out;
    if (!(fstype = libhal_volume_get_fstype(volume)))
        goto out;
    if (!(dev = libhal_device_get_property_string(context, did, "block.device",
                                                  (DBusError *)NULL)))
        goto out;
    mountp = get_mount_point(dev, label);
    if (!mountp)
        goto out;
    device = get_device(mountp, did, dev, label, fstype, volume, drive);
    if(!is_mounted(device)) {
        free_device(device);
        goto out;
    }
    if (!device)
        goto out;
    consider_fstab(device);

    device->hook = malloc(2*sizeof(char*)); 
    if(!file_exists(HOOK_PATH)) {
        device->hook[0] = get_hook(device, "mount");
        device->hook[1] = get_hook(device, "umount");
    }
    else {
        device->hook[0] = NULL;
        device->hook[1] = NULL;
    }

    if (file_exists(device->mountp) < 0)
        mkdir(device->mountp, 0750);
    do_mount(device) < 0 ? free_device(device) : add_to_device_list(device);

    if (device) {
        if (!add_fstab_entry(device))
            device->should_remove_entry = 1;
        if (debug_mode_flag)
            debug_dump_device(device);
    }

    if (device->hook[0]) run_hook(0, device);

out:
    if (mountable)
        libhal_free_string(mountable);
    if (label)
        libhal_free_string(label);
}