Пример #1
0
static inline void undo_rm_helper( entry_id_t * id, const char *last_known_path,
#ifdef _HSM_LITE
                             const char *bkpath
#endif
                             )
{
    entry_id_t new_id;
    recov_status_t st;
    attr_set_t     attrs, new_attrs;
    int rc;

    /* XXX src path must be in the same filesystem as backend
     * because it we be renamed */

    if ( EMPTY_STRING( last_known_path ) )
    {
        fprintf(stderr, "Last filesystem path is not known for fid "DFID", backend_path=%s.\n",
                PFID(id), bkpath);
        fprintf(stderr, " ----> skipped\n");
        return;
    }

    printf("Restoring '%s'...\n", last_known_path );

    ATTR_MASK_INIT(&attrs);
    ATTR_MASK_SET(&attrs, fullpath);
    strcpy( ATTR(&attrs, fullpath), last_known_path );

    if ( !EMPTY_STRING( bkpath ) )
    {
        ATTR_MASK_SET(&attrs, backendpath);
        strcpy( ATTR(&attrs, backendpath), bkpath );
    }

    /* copy file to Lustre */
    ATTR_MASK_INIT(&new_attrs);
    st = rbhext_recover( id, &attrs, &new_id, &new_attrs, NULL );
    if ((st == RS_FILE_OK) || (st == RS_FILE_DELTA)|| (st == RS_FILE_EMPTY)
        ||  (st == RS_NON_FILE))
    {
        printf("Success\n");
        /* discard entry from remove list */
        if ( ListMgr_SoftRemove_Discard(&lmgr, id) != 0 )
            fprintf(stderr, "Error: could not remove previous id "DFID" from database\n", PFID(id) );
        /* clean read-only attrs */
        new_attrs.attr_mask &= ~readonly_attr_set;
        /* insert or update it in the db */
        rc = ListMgr_Insert( &lmgr, &new_id, &new_attrs, TRUE );
        if ( rc == 0 )
            printf("Entry successfully updated in the dabatase\n");
        else
            fprintf(stderr, "ERROR %d inserting entry in the database\n", rc );
    }
    else
    {
        printf("ERROR\n");
    }
}
Пример #2
0
static int recov_resume(int retry_errors)
{
    struct lmgr_iterator_t *it;
    int rc, st;
    entry_id_t id, new_id;
    attr_set_t attrs, new_attrs;
    char buff[128];

    /* TODO iter opt */
    it = ListMgr_RecovResume(&lmgr, path_filter, retry_errors, NULL);
    if (it == NULL) {
        fprintf(stderr,
                "ERROR: cannot get the list of entries to be recovered\n");
        return -1;
    }

    attrs.attr_mask = RECOV_ATTR_MASK;

    while (!terminate &&
           ((rc =
             ListMgr_RecovGetNext(it, &id, &attrs, NULL)) != DB_END_OF_LIST)) {
        if (rc) {
            fprintf(stderr, "ERROR %d getting entry from recovery table\n", rc);
            ListMgr_CloseIterator(it);
            return rc;
        }

        FormatFileSize(buff, 128, ATTR(&attrs, size));

        if (ATTR_MASK_TEST(&attrs, fullpath))
            printf("Restoring %s (%s)...", ATTR(&attrs, fullpath), buff);
        else
            printf("Restoring " DFID " (%s)...", PFID(&id), buff);

        /* TODO process entries asynchronously, in parallel, in separate
         * threads */
        st = rbhext_recover(&id, &attrs, &new_id, &new_attrs, NULL);

        if ((st == RS_FILE_OK) || (st == RS_FILE_EMPTY) || (st == RS_NON_FILE)
            || (st == RS_FILE_DELTA)) {
            /* don't insert readonly attrs */
            new_attrs.attr_mask &= ~readonly_attr_set;

            /* insert the entry in the database, and update recovery status */
            rc = ListMgr_Insert(&lmgr, &new_id, &new_attrs, true);
            if (rc) {
                fprintf(stderr, "DB insert failure for '%s'\n",
                        ATTR(&new_attrs, fullpath));
                st = RS_ERROR;
            }
        }

        /* old id must be used for impacting recovery table */
        if (ListMgr_RecovSetState(&lmgr, &id, st))
            st = RS_ERROR;

        switch (st) {
        case RS_FILE_OK:
            printf(" OK\n");
            break;
        case RS_FILE_DELTA:
            printf(" OK (old version)\n");
            break;
        case RS_NON_FILE:
            printf(" OK (non-file)\n");
            break;
        case RS_FILE_EMPTY:
            printf(" OK (empty file)\n");
            break;
        case RS_NOBACKUP:
            printf(" No backup available\n");
            break;
        case RS_ERROR:
            printf(" FAILED\n");
            break;
        default:
            printf(" ERROR st=%d, rc=%d\n", st, rc);
            break;
        }

        /* reset mask */
        attrs.attr_mask = RECOV_ATTR_MASK;
    }

    return 0;
}