Exemplo n.º 1
0
/**
 * Get the first operation for a given id.
 * @return an operation to be processed when it is possible.
 *         NULL else. 
 *        
 */
entry_proc_op_t *id_constraint_get_first_op( entry_id_t * p_id )
{
    unsigned int   hash_index;
    id_constraint_item_t *p_curr;
    entry_proc_op_t *p_op = NULL;

    /* compute id hash value */
    hash_index = hash_id( p_id, ID_HASH_SIZE );

    P( id_hash[hash_index].lock );

    for ( p_curr = id_hash[hash_index].id_list_first; p_curr != NULL; p_curr = p_curr->p_next )
    {
        if ( entry_id_equal( p_id, &p_curr->op_ptr->entry_id ) )
        {
            p_op = p_curr->op_ptr;
            break;
        }
    }
#ifdef _DEBUG_ID_CONSTRAINT
    if ( p_op )
       printf( "first op on id "DFID" at stage %u (list %u)\n",
               PFID(&p_op->entry_id), p_op->pipeline_stage, hash_index );
    else
    {

        printf( "no registered operation on "DFID"?\n", PFID(p_id));
        printf( "etat de la file %u:\n", hash_index );
        for ( p_curr = id_hash[hash_index].id_list_first; p_curr != NULL; p_curr = p_curr->p_next )
            printf( DFID"\n", PFID(&p_curr->op_ptr->entry_id) );
    }
#endif
    V( id_hash[hash_index].lock );
    return p_op;

}
Exemplo n.º 2
0
/**
 * List contents of the given id/path list
 */
static int list_contents(char ** id_list, int id_count)
{
    wagon_t *ids;
    int i, rc;
    attr_set_t root_attrs;
    entry_id_t root_id;
    int is_id;

    rc = retrieve_root_id(&root_id);
    if (rc)
        return rc;

    ids = MemCalloc(id_count, sizeof(wagon_t));
    if (!ids)
        return -ENOMEM;

    for (i = 0; i < id_count; i++)
    {
        is_id = TRUE;
        /* is it a path or fid? */
        if (sscanf(id_list[i], SFID, RFID(&ids[i].id)) != FID_SCAN_CNT)
        {
            is_id = FALSE;
            /* take it as a path */
            rc = Path2Id(id_list[i], &ids[i].id);
            if (!rc) {
                ids[i].fullname = id_list[i];
                if (FINAL_SLASH(ids[i].fullname))
                    REMOVE_FINAL_SLASH(ids[i].fullname);
            }
        } else {
#if _HAVE_FID
            /* Take it as an FID. */
            char path[RBH_PATH_MAX];
            rc = Lustre_GetFullPath( &ids[i].id, path, sizeof(path));
            if (!rc)
                ids[i].fullname = strdup(path);
#endif
        }

        if (rc) {
            DisplayLog(LVL_MAJOR, FIND_TAG, "Invalid parameter: %s: %s",
                       id_list[i], strerror(-rc));
            goto out;
        }

        if ((prog_options.bulk != force_nobulk) &&
            (id_count == 1) && entry_id_equal(&ids[i].id, &root_id))
        {
            /* the ID is FS root: use list_bulk instead */
            DisplayLog(LVL_DEBUG, FIND_TAG, "Optimization: switching to bulk DB request mode");
            mkfilters(FALSE); /* keep dirs */
            MemFree(ids);
            return list_bulk();
        }

        /* get root attrs to print it (if it matches program options) */
        root_attrs.attr_mask = disp_mask | query_mask;
        rc = ListMgr_Get(&lmgr, &ids[i].id, &root_attrs);
        if (rc == 0)
            dircb(&ids[i], &root_attrs, 1, NULL);
        else
        {
            DisplayLog(LVL_VERB, FIND_TAG, "Notice: no attrs in DB for %s", id_list[i]);

            if (!is_id)
            {
                struct stat st;
                ATTR_MASK_SET(&root_attrs, fullpath);
                strcpy(ATTR(&root_attrs, fullpath), id_list[i]);

                if (lstat(ATTR(&root_attrs, fullpath ), &st) == 0)
                {
                    PosixStat2EntryAttr(&st, &root_attrs, TRUE);
                    ListMgr_GenerateFields( &root_attrs, disp_mask | query_mask);
                }
            }
            else if (entry_id_equal(&ids[i].id, &root_id))
            {
                /* this is root id */
                struct stat st;
                ATTR_MASK_SET(&root_attrs, fullpath);
                strcpy(ATTR(&root_attrs, fullpath), config.global_config.fs_path);

                if (lstat(ATTR(&root_attrs, fullpath ), &st) == 0)
                {
                    PosixStat2EntryAttr(&st, &root_attrs, TRUE);
                    ListMgr_GenerateFields( &root_attrs, disp_mask | query_mask);
                }
            }

            dircb(&ids[i], &root_attrs, 1, NULL);
        }

        rc = rbh_scrub(&lmgr, &ids[i], 1, disp_mask | query_mask, dircb, NULL);
    }

out:
    /* ids have been processed, free them */
    MemFree(ids);
    return rc;
}