From patchwork Tue Dec 13 22:52:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 131210 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from rcsinet15.oracle.com (rcsinet15.oracle.com [148.87.113.117]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "rcsinet15.oracle.com", Issuer "VeriSign Class 3 International Server CA - G3" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id 2D2131007D3 for ; Wed, 14 Dec 2011 09:52:38 +1100 (EST) Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pBDMqX2v003194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 13 Dec 2011 22:52:34 GMT Received: from oss.oracle.com (oss.oracle.com [141.146.12.120]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id pBDMqW1e010947 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 13 Dec 2011 22:52:32 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1RabD6-000625-2t; Tue, 13 Dec 2011 14:52:32 -0800 Received: from acsinet13.oracle.com ([141.146.126.235]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1RabD3-00061y-PA for fedfs-utils-devel@oss.oracle.com; Tue, 13 Dec 2011 14:52:29 -0800 Received: from mail-vx0-f171.google.com (mail-vx0-f171.google.com [209.85.220.171]) by acsinet13.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id pBDMov1H021828 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=FAIL) for ; Tue, 13 Dec 2011 22:52:29 GMT Received: by mail-vx0-f171.google.com with SMTP id fo1so205521vcb.2 for ; Tue, 13 Dec 2011 14:52:29 -0800 (PST) Received: by 10.220.151.137 with SMTP id c9mr3043348vcw.37.1323816749096; Tue, 13 Dec 2011 14:52:29 -0800 (PST) Received: from degas.1015granger.net (adsl-99-26-161-222.dsl.sfldmi.sbcglobal.net. [99.26.161.222]) by mx.google.com with ESMTPS id n20sm520243vdd.18.2011.12.13.14.52.27 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 13 Dec 2011 14:52:28 -0800 (PST) From: Chuck Lever To: fedfs-utils-devel@oss.oracle.com Date: Tue, 13 Dec 2011 17:52:27 -0500 Message-ID: <20111213225226.15402.83300.stgit@degas.1015granger.net> In-Reply-To: <20111213224842.15402.340.stgit@degas.1015granger.net> References: <20111213224842.15402.340.stgit@degas.1015granger.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Flow-Control-Info: class=ISPs ip=209.85.220.171 ct-class=G1 ct-vol1=0 ct-vol2=0 ct-vol3=0 ct-risk=0 ct-spam1=0 ct-spam2=0 ct-bulk=0 rcpts=1 size=8031 Subject: [fedfs-utils] [PATCH 10/12] libnsdb: struct fedfs_fsl object management X-BeenThere: fedfs-utils-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list Reply-To: fedfs-utils Developers List-Id: fedfs-utils Developers List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: fedfs-utils-devel-bounces@oss.oracle.com Errors-To: fedfs-utils-devel-bounces@oss.oracle.com X-Source-IP: ucsinet22.oracle.com [156.151.31.94] X-CT-RefId: str=0001.0A090207.4EE7D732.006B:SCFSTAT3865452, ss=1, re=-6.300, fgs=0 Expose a richer API for managing struct fedfs_fsl objects. Today these are returned by the FSN resolution API, thus they are created only inside the library, on behalf of nsdb_resolve_fsn_s(). But we also want to use them to allow callers outside of libnsdb to pass in a full set of locations information when creating FSL records. Signed-off-by: Chuck Lever --- src/fedfsd/svc.c | 2 - src/include/nsdb.h | 23 +++++++++ src/libnsdb/fileserver.c | 108 ++++++++++++++++++++++++++++++++++++++---- src/nsdbc/nsdb-list.c | 2 - src/nsdbc/nsdb-resolve-fsn.c | 2 - src/resolve-junction/main.c | 2 - 6 files changed, 124 insertions(+), 15 deletions(-) diff --git a/src/fedfsd/svc.c b/src/fedfsd/svc.c index 3b08272..291afdf 100644 --- a/src/fedfsd/svc.c +++ b/src/fedfsd/svc.c @@ -838,7 +838,7 @@ fedfsd_svc_lookup_junction_1(SVCXPRT *xprt) if (result.status != FEDFS_OK) break; result.status = fedfsd_prepare_fedfsfsl_array(fsls, resok); - nsdb_free_fsls(fsls); + nsdb_free_fedfs_fsls(fsls); break; default: result.status = FEDFS_ERR_SVRFAULT; diff --git a/src/include/nsdb.h b/src/include/nsdb.h index 942db23..b18e011 100644 --- a/src/include/nsdb.h +++ b/src/include/nsdb.h @@ -108,6 +108,28 @@ struct fedfs_fsl { }; /** + ** API to manage struct fedfs_fsl objects + **/ + +/** + * Allocate a fresh struct fedfs_fsl and init its fields to standard defaults + */ +__attribute_malloc__ +struct fedfs_fsl * + nsdb_new_fedfs_fsl(FedFsFslType type); + +/** + * Release a struct fedfs_fsl + */ +void nsdb_free_fedfs_fsl(struct fedfs_fsl *fsl); + +/** + * Release a list of struct fedfs_fsls + */ +void nsdb_free_fedfs_fsls(struct fedfs_fsl *fsls); + + +/** ** API to manage NSDB objects and the associated X.509 cert store **/ @@ -321,7 +343,6 @@ FedFsStatus nsdb_split_nce_dn_s(nsdb_t host, const char *nce, FedFsStatus nsdb_resolve_fsn_s(nsdb_t host, const char *nce, const char *fsn_uuid, struct fedfs_fsl **fsls, unsigned int *ldap_err); -void nsdb_free_fsls(struct fedfs_fsl *fsls); /** ** NSDB fileserver operations defined by this implementation diff --git a/src/libnsdb/fileserver.c b/src/libnsdb/fileserver.c index b1b3deb..aa3a5b2 100644 --- a/src/libnsdb/fileserver.c +++ b/src/libnsdb/fileserver.c @@ -51,12 +51,20 @@ static struct timeval nsdb_ldap_timeout = { 5, 0 }; /** * Free a single struct fedfs_fsl * - * @param fsl pointer to fsl to free + * @param fsl pointer to struct fedfs_fsl to free */ -static void -nsdb_free_fsl(struct fedfs_fsl *fsl) +void +nsdb_free_fedfs_fsl(struct fedfs_fsl *fsl) { - free(fsl->fl_u.fl_nfsfsl.fn_path); + switch (fsl->fl_type) { + case FEDFS_NFS_FSL: + free(fsl->fl_u.fl_nfsfsl.fn_path); + break; + default: + xlog(L_ERROR, "%s: Unrecognized FSL type", __func__); + return; + } + nsdb_free_string_array(fsl->fl_description); nsdb_free_string_array(fsl->fl_annotations); free(fsl->fl_dn); @@ -65,21 +73,102 @@ nsdb_free_fsl(struct fedfs_fsl *fsl) /** * Free a list of fedfs_fsl structures + * * @param fsls pointer to first element of a list of struct fedfs_fsl */ void -nsdb_free_fsls(struct fedfs_fsl *fsls) +nsdb_free_fedfs_fsls(struct fedfs_fsl *fsls) { struct fedfs_fsl *fsl; while (fsls != NULL) { fsl = fsls; fsls = fsl->fl_next; - nsdb_free_fsl(fsl); + nsdb_free_fedfs_fsl(fsl); } } /** + * Allocate a new struct fedfs_fsl + * + * @return a malloc'd struct fedfs_fsl, or NULL + * + * Caller must free the returned memory with free(3) + */ +__attribute_malloc__ +static struct fedfs_fsl * +nsdb_alloc_fedfs_fsl(void) +{ + return calloc(1, sizeof(struct fedfs_fsl)); +} + +/** + * Initialize an NFS FSL to recommended defaults + * + * @param fsl pointer to struct fedfs_fsl + * + * See NSDB protocol draft Section 5.1.3.2. + */ +static void +nsdb_init_fedfs_nfs_fsl(struct fedfs_fsl *fsl) +{ + struct fedfs_nfs_fsl *nfsfsl = &fsl->fl_u.fl_nfsfsl; + + nfsfsl->fn_majorver = 4; + nfsfsl->fn_minorver = 0; + nfsfsl->fn_currency = -1; + nfsfsl->fn_gen_writable = false; + nfsfsl->fn_gen_going = false; + nfsfsl->fn_gen_split = true; + nfsfsl->fn_trans_rdma = true; + nfsfsl->fn_class_simul = 0; + nfsfsl->fn_class_handle = 0; + nfsfsl->fn_class_fileid = 0; + nfsfsl->fn_class_writever = 0; + nfsfsl->fn_class_change = 0; + nfsfsl->fn_class_readdir = 0; + nfsfsl->fn_readrank = 0; + nfsfsl->fn_readorder = 0; + nfsfsl->fn_writerank = 0; + nfsfsl->fn_writeorder = 0; + nfsfsl->fn_varsub = false; + nfsfsl->fn_validfor = 0; +} + +/** + * Allocate a new struct fedfs_fsl and initialize its fields + * + * @return a malloc'd struct fedfs_fsl, or NULL + * + * Caller must free the returned memory with nsdb_free_fedfs_fsl() + */ +__attribute_malloc__ +struct fedfs_fsl * +nsdb_new_fedfs_fsl(FedFsFslType type) +{ + struct fedfs_fsl *new; + + new = nsdb_alloc_fedfs_fsl(); + if (new == NULL) + return NULL; + + switch (type) { + case FEDFS_NFS_FSL: + nsdb_init_fedfs_nfs_fsl(new); + break; + default: + xlog(L_ERROR, "%s: Unrecognized FSL type", __func__); + free(new); + return NULL; + } + + new->fl_nsdbport = LDAP_PORT; + new->fl_type = type; + new->fl_fslttl = 300; + return new; +} + +/** * Parse DN for an LDAP server's NSDB container info * * @param ld an initialized LDAP descriptor @@ -755,12 +844,11 @@ nsdb_resolve_fsn_parse_entry(LDAP *ld, LDAPMessage *entry, xlog(D_CALL, "%s: parsing entry", __func__); - new = calloc(1, sizeof(struct fedfs_fsl)); + new = nsdb_alloc_fedfs_fsl(); if (new == NULL) { xlog(L_ERROR, "%s: Failed to allocate new fsl", __func__); return FEDFS_ERR_SVRFAULT; } - new->fl_type = (FedFsFslType) -1; dn = ldap_get_dn(ld, entry); if (dn != NULL ) { @@ -893,7 +981,7 @@ nsdb_resolve_fsn_find_entry_s(LDAP *ld, const char *nce, const char *fsn_uuid, xlog(D_CALL, "%s: returning fsls", __func__); *fsls = tmp; } else - nsdb_free_fsls(tmp); + nsdb_free_fedfs_fsls(tmp); return retval; } @@ -909,7 +997,7 @@ nsdb_resolve_fsn_find_entry_s(LDAP *ld, const char *nce, const char *fsn_uuid, * * If caller did not provide an NCE, discover one by querying the NSDB. * - * Caller must free the list returned in "fsls" using nsdb_free_fsls(). + * Caller must free the list returned in "fsls" using nsdb_free_fedfs_fsls(). */ FedFsStatus nsdb_resolve_fsn_s(nsdb_t host, const char *nce, const char *fsn_uuid, diff --git a/src/nsdbc/nsdb-list.c b/src/nsdbc/nsdb-list.c index 77f0567..16b79a5 100644 --- a/src/nsdbc/nsdb-list.c +++ b/src/nsdbc/nsdb-list.c @@ -116,7 +116,7 @@ nsdb_list_resolve_and_display_fsn(nsdb_t host, const char *nce, const char *fsn_ switch (retval) { case FEDFS_OK: nsdb_list_display_fsls(fsls); - nsdb_free_fsls(fsls); + nsdb_free_fedfs_fsls(fsls); break; case FEDFS_ERR_NSDB_NOFSL: printf(" No FSL entries found\n"); diff --git a/src/nsdbc/nsdb-resolve-fsn.c b/src/nsdbc/nsdb-resolve-fsn.c index d317575..e4d99fc 100644 --- a/src/nsdbc/nsdb-resolve-fsn.c +++ b/src/nsdbc/nsdb-resolve-fsn.c @@ -314,7 +314,7 @@ main(int argc, char **argv) case FEDFS_OK: printf("For FSN UUID %s:\n\n", fsn_uuid); nsdb_resolve_fsn_display_fsls(fsls); - nsdb_free_fsls(fsls); + nsdb_free_fedfs_fsls(fsls); break; case FEDFS_ERR_NSDB_NONCE: if (nce == NULL) diff --git a/src/resolve-junction/main.c b/src/resolve-junction/main.c index e6f4091..00f7a1f 100644 --- a/src/resolve-junction/main.c +++ b/src/resolve-junction/main.c @@ -294,7 +294,7 @@ resolve_junction(const char *pathname) switch (status) { case FEDFS_OK: result = resolve_junction_display_results(fsls); - nsdb_free_fsls(fsls); + nsdb_free_fedfs_fsls(fsls); break; case FEDFS_ERR_NSDB_NOFSL: fprintf(stdout, "No results\n");