Changeset 9222

Show
Ignore:
Timestamp:
03/07/12 17:53:55 (15 months ago)
Author:
sampson
Message:

1. Made pvfs2-gencred return specific error codes.
2. Made client applications report (via gossip) errors generating credentials.
3. Changed the PVFS_errno_to_error function to convert errno values to PVFS errors.
This function is also used by the directio mgmt code, so I:
4. Fixed error-handling in the directio mgmt code.
5. Added a debug item "mgmt" to debug directio mgmt code.

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/include/pvfs2-debug.h

    r9123 r9222  
    217217    { "bstream", GOSSIP_BSTREAM_DEBUG }, 
    218218    /* Debug trove in direct io mode */ 
    219     {"directio", GOSSIP_DIRECTIO_DEBUG}, 
     219    { "directio", GOSSIP_DIRECTIO_DEBUG }, 
     220    /* Debug direct io thread management */ 
     221    { "mgmt", GOSSIP_MGMT_DEBUG }, 
    220222    /* Debug mirroring process */ 
    221     {"mirror",GOSSIP_MIRROR_DEBUG}, 
     223    { "mirror",GOSSIP_MIRROR_DEBUG }, 
    222224    /* Windows client */ 
    223     {"win_client", GOSSIP_WIN_CLIENT_DEBUG}, 
     225    { "win_client", GOSSIP_WIN_CLIENT_DEBUG }, 
    224226    /* Debug robust security code */ 
    225     {"security", GOSSIP_SECURITY_DEBUG}, 
     227    { "security", GOSSIP_SECURITY_DEBUG }, 
    226228    /* Client User Interface */ 
    227     {"usrint", GOSSIP_USRINT_DEBUG}, 
     229    { "usrint", GOSSIP_USRINT_DEBUG }, 
    228230    /* Everything except the periodic events.  Useful for debugging */ 
    229231    { "verbose", 
  • trunk/include/pvfs2-types.h

    r9170 r9222  
    911911                             abs(error))) & ~mask)];       \ 
    912912    }                                                      \ 
    913     return ret;                                            \ 
     913    return ret;                                            \ 
    914914}                                                          \ 
    915915PVFS_error PVFS_errno_to_error(int err)                    \ 
    916916{                                                          \ 
    917917    PVFS_error e = 0;                                      \ 
    918     \ 
     918                                                           \ 
    919919    for(; e < PVFS_ERRNO_MAX; ++e)                         \ 
    920920    {                                                      \ 
    921921        if(PINT_errno_mapping[e] == err)                   \ 
    922922        {                                                  \ 
    923             return e;                                      \ 
     923            return e | PVFS_ERROR_BIT;                     \ 
    924924        }                                                  \ 
    925925    }                                                      \ 
    926     return 0;                                              \ 
     926    return err;                                            \ 
    927927}                                                          \ 
    928928DECLARE_ERRNO_MAPPING() 
  • trunk/src/apps/admin/pvfs2-gencred.c

    r9170 r9222  
    6161        if (cnt == -1) 
    6262        { 
    63             return -1; 
     63            return errno; 
    6464        } 
    6565    } 
     
    8989                            optarg); 
    9090                    usage(); 
    91                     return EXIT_FAILURE; 
     91                    return EINVAL; 
    9292                } 
    9393                break; 
     
    9898            default: 
    9999                usage(); 
    100                 return EXIT_FAILURE; 
     100                return EINVAL; 
    101101        } 
    102102    } 
     
    117117    if (issuer == NULL) 
    118118    { 
    119         return EXIT_FAILURE; 
     119        return ENOMEM; 
    120120    } 
    121121    /* issuer field for clients is prefixed with "C:" */ 
     
    132132    { 
    133133        free(issuer); 
    134         return EXIT_FAILURE; 
     134        return ENOMEM; 
    135135    } 
    136136    for (i = 0; i < ngroups; i++) 
     
    158158    if (keyfile == NULL) 
    159159    { 
     160        int err = errno; 
    160161        perror(keypath); 
    161         return EXIT_FAILURE; 
     162        return err; 
    162163    } 
    163164 
     
    165166    if (ret == -1) 
    166167    { 
     168        int err = errno; 
    167169        perror("stat"); 
    168170        fclose(keyfile); 
    169         return EXIT_FAILURE; 
     171        return err; 
    170172    } 
    171173    if (stats.st_mode & (S_IROTH | S_IWOTH)) 
     
    180182        ERR_print_errors_fp(stderr); 
    181183        fclose(keyfile); 
    182         return EXIT_FAILURE; 
     184        return ENODATA; 
    183185    } 
    184186 
     
    190192    { 
    191193        EVP_PKEY_free(privkey); 
    192         return EXIT_FAILURE; 
     194        return ENOMEM; 
    193195    } 
    194196 
     
    217219        EVP_MD_CTX_cleanup(&mdctx); 
    218220        EVP_PKEY_free(privkey); 
    219         return EXIT_FAILURE; 
     221        return ENODATA; 
    220222    } 
    221223    ret = EVP_SignFinal(&mdctx, cred->signature, &cred->sig_size, privkey); 
     
    226228        EVP_MD_CTX_cleanup(&mdctx); 
    227229        EVP_PKEY_free(privkey); 
    228         return EXIT_FAILURE; 
     230        return ENODATA; 
    229231    } 
    230232 
     
    259261    { 
    260262        fputs("error: stdout is a tty\n", stderr); 
    261         return EXIT_FAILURE; 
     263        return EIO; 
    262264    } 
    263265 
    264266    encode_PVFS_credential(&pptr, cred); 
    265267    ret = safe_write(STDOUT_FILENO, buf, sizeof(buf)); 
    266     if (ret == -1) 
    267     { 
     268    if (ret) 
     269    {         
    268270        perror("write"); 
    269         return EXIT_FAILURE; 
     271        return ret; 
    270272    } 
    271273 
     
    326328            fprintf(stderr, "unknown user -- %s\n", opts.user); 
    327329        } 
    328         return EXIT_FAILURE; 
     330        return EINVAL; 
    329331    } 
    330332 
     
    361363            fprintf(stderr, "unknown group -- %s\n", opts.group); 
    362364        } 
    363         return EXIT_FAILURE; 
     365        return EINVAL; 
    364366    } 
    365367 
     
    368370        fprintf(stderr, "error: only %s and root can generate a credential " 
    369371                "for %s\n", pwd->pw_name, pwd->pw_name); 
    370         return EXIT_FAILURE; 
     372        return EPERM; 
    371373    } 
    372374 
     
    375377        fprintf(stderr, "error: cannot generate a credential for group %s: " 
    376378                "Permission denied\n", grp->gr_name); 
    377         return EXIT_FAILURE; 
     379        return EPERM; 
    378380    } 
    379381 
     
    386388        fprintf(stderr, "error: unable to get group list for user %s\n", 
    387389                pwd->pw_name); 
    388         return EXIT_FAILURE; 
     390        return ENOENT; 
    389391    } 
    390392    if (groups[0] != grp->gr_gid) 
     
    401403    if (ngroups == -1) 
    402404    { 
     405        int err = errno; 
    403406        fprintf(stderr, "error: unable to get group list for user %s: %s\n", 
    404407                pwd->pw_name, strerror(errno)); 
    405         return EXIT_FAILURE; 
     408        return err; 
    406409    } 
    407410 
     
    436439    free(credential.issuer); 
    437440    free(credential.group_array); 
     441 
    438442    return EXIT_SUCCESS; 
    439443} 
  • trunk/src/common/mgmt/pint-worker-per-op.c

    r7450 r9222  
    8080    if(ret != 0) 
    8181    { 
    82         return PVFS_get_errno_mapping(ret); 
     82        return -PVFS_errno_to_error(ret); 
    8383    } 
    8484 
     
    9090    { 
    9191        pthread_attr_destroy(&attr); 
    92         return PVFS_get_errno_mapping(ret); 
     92        return -PVFS_errno_to_error(ret); 
    9393    } 
    9494 
     
    100100    if(ret != 0) 
    101101    { 
    102         return PVFS_errno_to_error(ret); 
     102        return -PVFS_errno_to_error(ret); 
    103103    } 
    104104 
  • trunk/src/common/mgmt/pint-worker-threaded-queues.c

    r8925 r9222  
    7474            free(w->threads); 
    7575            gen_cond_destroy(&w->cond); 
     76            goto exit; 
    7677        } 
    7778        gossip_debug(GOSSIP_MGMT_DEBUG,"%s:thread_id %d:thread #%d.\n" 
     
    529530    ret = pthread_create(&tentry->thread_id, NULL, 
    530531                         PINT_worker_queues_thread_function, tentry); 
    531     if(ret < 0) 
     532    if(ret != 0) 
    532533    { 
    533534        /* convert to PVFS error */ 
    534         return PVFS_errno_to_error(ret); 
     535        return -PVFS_errno_to_error(ret); 
    535536    } 
    536537    return 0; 
     
    554555 
    555556    ret = pthread_join(tentry->thread_id, &ptr); 
    556     if(ret < 0) 
     557    if(ret != 0) 
    557558    { 
    558559        return PVFS_errno_to_error(ret); 
  • trunk/src/common/misc/pvfs2-util.c

    r9177 r9222  
    183183    struct sigaction newsa, oldsa; 
    184184    pid_t pid; 
    185     int filedes[2]; 
     185    int filedes[2], errordes[2]; 
    186186    int ret; 
    187187 
     
    195195    sigaction(SIGCHLD, &newsa, &oldsa); 
    196196 
     197    /* pipe to read credential from stdout of pvfs2-gencred */ 
    197198    ret = pipe(filedes); 
     199    if (ret == -1) 
     200    { 
     201        return -PVFS_errno_to_error(errno); 
     202    } 
     203    /* pipe to read any error messages from stderr of pvfs2-gencred */ 
     204    ret = pipe(errordes); 
    198205    if (ret == -1) 
    199206    { 
     
    210217 
    211218        close(STDERR_FILENO); 
     219        dup(errordes[1]); 
    212220        close(STDOUT_FILENO); 
    213221        dup(filedes[1]); 
     
    245253    { 
    246254        close(filedes[1]); 
     255        close(errordes[1]); 
    247256        ret = -PVFS_errno_to_error(errno); 
    248257    } 
    249258    else 
    250259    { 
    251         char buf[sizeof(PVFS_credential)+extra_size_PVFS_credential]; 
    252         ssize_t total = 0; 
    253         ssize_t cnt; 
     260        char buf[sizeof(PVFS_credential)+extra_size_PVFS_credential], 
     261             ebuf[512]; 
     262        ssize_t total = 0, etotal = 0; 
     263        ssize_t cnt, ecnt; 
    254264 
    255265        /* close write end so we get EOF when child exits */ 
     266        close(errordes[1]); 
    256267        close(filedes[1]); 
    257268 
     269        /* read credential */ 
    258270        do 
    259271        { 
    260             do cnt = read(filedes[0], buf+total, (sizeof(buf) - total)); 
    261             while (cnt == -1 && errno == EINTR); 
     272            do 
     273            { 
     274                cnt = read(filedes[0], buf+total, (sizeof(buf) - total)); 
     275            } while (cnt == -1 && errno == EINTR); 
    262276            total += cnt; 
    263277        } while (cnt > 0); 
     
    280294                ret = PINT_copy_credential(&tmp, cred); 
    281295            } 
     296            else if (WIFEXITED(rc)) 
     297            {                 
     298                /* error code from pvfs2_gencred */ 
     299                ret = -PVFS_errno_to_error(WEXITSTATUS(rc)); 
     300            } 
    282301            else 
    283302            { 
    284                 /* nlmills: TODO: find a more appropriate error code */ 
     303                /* catch-all error */ 
    285304                ret = -PVFS_EINVAL; 
    286305            } 
     306 
     307            /* read errors and warnings */ 
     308            do 
     309            { 
     310                do 
     311                { 
     312                    ecnt = read(errordes[0], ebuf+etotal,  
     313                                (sizeof(ebuf) - etotal)); 
     314                } while (ecnt == -1 && errno == EINTR); 
     315                etotal += ecnt; 
     316            } while (ecnt > 0 && etotal < sizeof(ebuf)); 
     317            /* null terminate */ 
     318            ebuf[(etotal < sizeof(ebuf)) ? etotal : sizeof(ebuf)] = '\0'; 
     319 
     320            /* print errors */ 
     321            if (etotal > 0) 
     322            { 
     323                char gbuf[600]; 
     324                snprintf(gbuf, sizeof(gbuf), "pvfs2_gencred: %s", ebuf); 
     325                gossip_err(gbuf); 
     326            } 
    287327        } 
    288328    } 
    289329 
    290330    close(filedes[0]); 
     331    close(errordes[0]); 
    291332    sigaction(SIGCHLD, &oldsa, NULL); 
    292333