示例#1
0
//!
//!
//!
//! @param[in] path
//! @param[in] bs
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure
//!
//! @pre
//!
//! @post
//!
static int stat_blobstore(const char *path, blobstore * bs)
{
    s64 size_mb = 0;
    s64 allocated_mb = 0;
    s64 reserved_mb = 0;
    s64 locked_mb = 0;
    s64 fs_size_mb = 0;
    struct statfs fs = { 0 };
    blobstore_meta meta = { {0} };

    blobstore_stat(bs, &meta);
    size_mb = meta.blocks_limit ? (meta.blocks_limit / 2048) : (-1L);   // convert sectors->MB
    allocated_mb = meta.blocks_limit ? (meta.blocks_allocated / 2048) : 0;
    reserved_mb = meta.blocks_limit ? ((meta.blocks_locked + meta.blocks_unlocked) / 2048) : 0;
    locked_mb = meta.blocks_limit ? (meta.blocks_locked / 2048) : (-1L);

    if (statfs(path, &fs) == -1) {
        LOGERROR("failed to stat %s: %s\n", path, strerror(errno));
        return EUCA_ERROR;
    }

    fs_size_mb = ((s64) fs.f_bsize) * ((s64) (fs.f_blocks / MEGABYTE));

    LOGINFO("disk space under %s\n", path);
    LOGINFO("                 %06ldMB limit (%.1f%% of the file system)\n", size_mb, ((double)size_mb / (double)fs_size_mb) * 100.0);
    LOGINFO("                 %06ldMB reserved for use (%.1f%% of limit)\n", reserved_mb, ((double)reserved_mb / (double)size_mb) * 100.0);
    LOGINFO("                 %06ldMB locked for use (%.1f%% of limit)\n", locked_mb, ((double)locked_mb / (double)size_mb) * 100.0);
    LOGINFO("                 %06ldMB allocated for use (%.1f%% of limit, %.1f%% of the file system)\n",
            allocated_mb, ((double)allocated_mb / (double)size_mb) * 100.0, ((double)allocated_mb / (double)fs_size_mb) * 100.0);
    return EUCA_OK;
}
示例#2
0
static int stat_blobstore (const char * conf_instances_path, const char * name, blobstore_meta * meta)
{
    bzero (meta, sizeof (blobstore_meta));
    char path [MAX_PATH]; 
    snprintf (path, sizeof (path), "%s/%s", conf_instances_path, name);

    // stat the file system and return those numbers even if blobstore does not exist
    if (statfs_path (path, &(meta->fs_bytes_size), &(meta->fs_bytes_available), &(meta->fs_id)) != OK) {
        return ERROR;
    }

    // get the size and params of the blobstore, if it exists
    blobstore * bs = blobstore_open (path, 
                                     0, // any size
                                     0, // no flags = do not create it
                                     BLOBSTORE_FORMAT_ANY, 
                                     BLOBSTORE_REVOCATION_ANY, 
                                     BLOBSTORE_SNAPSHOT_ANY);
    if (bs == NULL)
        return OK;
    blobstore_stat (bs, meta);
    blobstore_close (bs);
    
    return OK;
}
示例#3
0
文件: imager.c 项目: sosilent/euca
static int stat_blobstore (const char * path, blobstore * bs) 
{
    blobstore_meta meta;
    blobstore_stat (bs, &meta);
    long long size_mb       = meta.blocks_limit ? (meta.blocks_limit / 2048) : (-1L); // convert sectors->MB
    long long allocated_mb  = meta.blocks_limit ? (meta.blocks_allocated / 2048) : 0;
    long long reserved_mb   = meta.blocks_limit ? ((meta.blocks_locked + meta.blocks_unlocked) / 2048) : 0;
    long long locked_mb     = meta.blocks_limit ? (meta.blocks_locked / 2048) : (-1L);

    struct statfs fs;
    if (statfs (path, &fs) == -1) { 
        logprintfl (EUCAERROR, "error: failed to stat %s: %s\n", path, strerror(errno));
        return 1;
    }
    long long fs_avail_mb = (long long)fs.f_bsize * (long long)(fs.f_bavail/MEGABYTE);
    long long fs_size_mb =  (long long)fs.f_bsize * (long long)(fs.f_blocks/MEGABYTE); 

    logprintfl (EUCAINFO, "disk space under %s\n", path);
    logprintfl (EUCAINFO, "                 %06lldMB limit (%.1f%% of the file system)\n",
                size_mb, 
                ((double)size_mb/(double)fs_size_mb)*100.0);
    logprintfl (EUCAINFO, "                 %06lldMB reserved for use (%.1f%% of limit)\n", 
                reserved_mb, 
                ((double)reserved_mb/(double)size_mb)*100.0 );
    logprintfl (EUCAINFO, "                 %06lldMB locked for use (%.1f%% of limit)\n", 
                locked_mb, 
                ((double)locked_mb/(double)size_mb)*100.0 );
    logprintfl (EUCAINFO, "                 %06lldMB allocated for use (%.1f%% of limit, %.1f%% of the file system)\n", 
                allocated_mb, 
                ((double)allocated_mb/(double)size_mb)*100.0,
                ((double)allocated_mb/(double)fs_size_mb)*100.0 );
    return 0;
}
示例#4
0
static void stat_blobstore (const char * conf_instances_path, const char * name, blobstore_meta * meta)
{
    bzero (meta, sizeof (blobstore_meta));
    char path [MAX_PATH]; 
    snprintf (path, sizeof (path), "%s/%s", conf_instances_path, name);
    blobstore * bs = blobstore_open (path, 
                                     0, // any size
                                     0, // no flags = do not create it
                                     BLOBSTORE_FORMAT_ANY, 
                                     BLOBSTORE_REVOCATION_ANY, 
                                     BLOBSTORE_SNAPSHOT_ANY);
    if (bs == NULL)
        return;
    blobstore_stat (bs, meta);
    blobstore_close (bs);
}
//!
//! Stats the blobstore (name) created under the given path.
//!
//! @param[in]  conf_instances_path path to where the instances information are stored
//! @param[in]  name name of the blobstore
//! @param[out] meta the blobstore metadata to retrieve
//!
//! @return EUCA_OK on success or the following error codes:
//!         \li EUCA_ACCESS_ERROR if we fail to access the requested blobstore
//!
//! @pre The conf_instance_path, name and meta fields must not be NULL.
//!
//! @post On success the meta fields have been updated
//!
static int stat_blobstore(const char *conf_instances_path, const char *name, blobstore_meta * meta)
{
    char path[EUCA_MAX_PATH] = "";
    blobstore *bs = NULL;

    bzero(meta, sizeof(blobstore_meta));
    snprintf(path, sizeof(path), "%s/%s", conf_instances_path, name);

    // stat the file system and return those numbers even if blobstore does not exist
    if (statfs_path(path, &(meta->fs_bytes_size), &(meta->fs_bytes_available), &(meta->fs_id)) != EUCA_OK) {
        return (EUCA_ACCESS_ERROR);
    }
    // get the size and params of the blobstore, if it exists (do not create)
    if ((bs = blobstore_open(path, 0, 0, BLOBSTORE_FORMAT_ANY, BLOBSTORE_REVOCATION_ANY, BLOBSTORE_SNAPSHOT_ANY)) == NULL)
        return (EUCA_OK);

    // stat and close our blobstore
    blobstore_stat(bs, meta);
    BLOBSTORE_CLOSE(bs);
    return (EUCA_OK);
}