@@ -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;
@@ -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
@@ -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,
@@ -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");
@@ -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)
@@ -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");
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 <chuck.lever@oracle.com> --- 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(-)