From 74982e6ae1919f81184d221b56aba7f153d188ed Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Mon, 27 Jan 2014 00:30:20 -0500 Subject: [PATCH] Windows: cm_GetAddrsU wrapper for VL_GetAddrsU cm_GetAddrsU() is a wrapper for the VL_GetAddrsU() RPC. The initial version is a bare bones replacement for the VL_GetAddrsU() call from cm_UpdateVolumeLocation(). Future changes will add caching. Change-Id: I7d51d98d8fd21b91f25424bdb795576ea44deab4 Reviewed-on: http://gerrit.openafs.org/10763 Tested-by: BuildBot Reviewed-by: Derrick Brashear Reviewed-by: Jeffrey Altman --- src/WINNT/afsd/NTMakefile | 2 + src/WINNT/afsd/cm_getaddrs.c | 120 +++++++++++++++++++++++++++++++++++ src/WINNT/afsd/cm_getaddrs.h | 42 ++++++++++++ src/WINNT/afsd/cm_volume.c | 55 ++++------------ 4 files changed, 176 insertions(+), 43 deletions(-) create mode 100644 src/WINNT/afsd/cm_getaddrs.c create mode 100644 src/WINNT/afsd/cm_getaddrs.h diff --git a/src/WINNT/afsd/NTMakefile b/src/WINNT/afsd/NTMakefile index 11b92047e..c53079d79 100644 --- a/src/WINNT/afsd/NTMakefile +++ b/src/WINNT/afsd/NTMakefile @@ -32,6 +32,7 @@ INCFILES =\ $(INCFILEDIR)\cm_conn.h \ $(INCFILEDIR)\cm_error.h \ $(INCFILEDIR)\cm_ioctl.h \ + $(INCFILEDIR)\cm_getaddrs.h \ $(INCFILEDIR)\cm_scache.h \ $(INCFILEDIR)\cm_server.h \ $(INCFILEDIR)\cm_user.h \ @@ -132,6 +133,7 @@ AFSDOBJS=\ $(OUT)\cm_direct.obj \ $(OUT)\cm_access.obj \ $(OUT)\cm_eacces.obj \ + $(OUT)\cm_getaddrs.obj \ $(OUT)\cm_callback.obj \ $(OUT)\cm_vnodeops.obj \ $(OUT)\cm_dir.obj \ diff --git a/src/WINNT/afsd/cm_getaddrs.c b/src/WINNT/afsd/cm_getaddrs.c new file mode 100644 index 000000000..d87aa3edf --- /dev/null +++ b/src/WINNT/afsd/cm_getaddrs.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2014 Your File System, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Secure Endpoints Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission from Secure Endpoints, Inc. and + * Your File System, Inc. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include "afsd.h" +#include "cm_getaddrs.h" + +/* + * cm_GetAddrsU takes as input a uuid and a unique value which + * represent the set of addresses that are required. These values + * are used as input to the VL_GetAddrsU RPC which returns a list + * of addresses. For each returned address a bucket in the provided + * arrays (serverFlags, serverNumber, serverUUID, serverUnique) + * are populated. The serverFlags array entries are filled with the + * 'Flags' value provided as input. 'serverNumber' is the server's + * IP address. + */ + +afs_uint32 +cm_GetAddrsU(cm_cell_t *cellp, cm_user_t *userp, cm_req_t *reqp, + afsUUID *Uuid, afs_int32 Unique, afs_int32 Flags, + int *index, + afs_int32 serverFlags[], + afs_int32 serverNumber[], + afsUUID serverUUID[], + afs_int32 serverUnique[]) +{ + afs_uint32 code = 0; + cm_conn_t *connp; + struct rx_connection *rxconnp; + afs_uint32 * addrp, nentries; + afs_int32 unique; + bulkaddrs addrs; + ListAddrByAttributes attrs; + afsUUID uuid; + int i; + + memset(&uuid, 0, sizeof(uuid)); + memset(&addrs, 0, sizeof(addrs)); + memset(&attrs, 0, sizeof(attrs)); + + attrs.Mask = VLADDR_UUID; + attrs.uuid = *Uuid; + + do { + code = cm_ConnByMServers(cellp->vlServersp, 0, userp, reqp, &connp); + if (code) + continue; + rxconnp = cm_GetRxConn(connp); + code = VL_GetAddrsU(rxconnp, &attrs, &uuid, &unique, &nentries, + &addrs); + rx_PutConnection(rxconnp); + } while (cm_Analyze(connp, userp, reqp, NULL, cellp, 0, NULL, NULL, + &cellp->vlServersp, NULL, code)); + + code = cm_MapVLRPCError(code, reqp); + + if (afsd_logp->enabled) { + char uuidstr[128]; + afsUUID_to_string(Uuid, uuidstr, sizeof(uuidstr)); + + if (code) + osi_Log2(afsd_logp, + "CALL VL_GetAddrsU serverNumber %s FAILURE, code 0x%x", + osi_LogSaveString(afsd_logp, uuidstr), + code); + else + osi_Log1(afsd_logp, "CALL VL_GetAddrsU serverNumber %s SUCCESS", + osi_LogSaveString(afsd_logp, uuidstr)); + } + + if (code) + return CM_ERROR_RETRY; + + if (nentries == 0) { + code = CM_ERROR_INVAL; + } else { + addrp = addrs.bulkaddrs_val; + for (i = 0; i < nentries && (*index) < NMAXNSERVERS; (*index)++, i++) { + serverFlags[*index] = Flags; + serverNumber[*index] = addrp[i]; + serverUUID[*index] = uuid; + serverUnique[*index] = unique; + } + } + xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs); + + return code; +} diff --git a/src/WINNT/afsd/cm_getaddrs.h b/src/WINNT/afsd/cm_getaddrs.h new file mode 100644 index 000000000..0f8984cf0 --- /dev/null +++ b/src/WINNT/afsd/cm_getaddrs.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2014 Your File System, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of Secure Endpoints Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission from Secure Endpoints, Inc. and + * Your File System, Inc. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CM_GETADDRS_H_ +#define _CM_GETADDRS_H_ + +#include + +extern afs_uint32 +cm_GetAddrsU(cm_cell_t *cellp, cm_user_t *userp, cm_req_t *reqp, + afsUUID *Uuid, afs_int32 Unique, afs_int32 Flags, int *index, + afs_int32 serverFlags[], afs_int32 serverNumber[], afsUUID serverUUID[], + afs_int32 serverUnique[]); + +#endif /* _CM_GETADDRS_H_ */ diff --git a/src/WINNT/afsd/cm_volume.c b/src/WINNT/afsd/cm_volume.c index 1b1a65c37..cf95d00d9 100644 --- a/src/WINNT/afsd/cm_volume.c +++ b/src/WINNT/afsd/cm_volume.c @@ -20,6 +20,7 @@ #include #include #include "afsd.h" +#include "cm_getaddrs.h" #include #include @@ -268,10 +269,8 @@ cm_GetEntryByID( struct cm_cell *cellp, afs_uint32 id, long cm_UpdateVolumeLocation(struct cm_cell *cellp, cm_user_t *userp, cm_req_t *reqp, cm_volume_t *volp) { - struct rx_connection *rxconnp; - cm_conn_t *connp; int i; - afs_uint32 j, k; + afs_uint32 j; cm_serverRef_t *tsrp; cm_server_t *tsp; struct sockaddr_in tsockAddr; @@ -401,6 +400,7 @@ long cm_UpdateVolumeLocation(struct cm_cell *cellp, cm_user_t *userp, cm_req_t * afs_int32 roID; afs_int32 bkID; afs_int32 serverNumber[NMAXNSERVERS]; + afs_int32 serverUnique[NMAXNSERVERS]; afs_int32 serverFlags[NMAXNSERVERS]; afsUUID serverUUID[NMAXNSERVERS]; afs_int32 rwServers_alldown = 1; @@ -420,6 +420,7 @@ long cm_UpdateVolumeLocation(struct cm_cell *cellp, cm_user_t *userp, cm_req_t * } memset(serverUUID, 0, sizeof(serverUUID)); + memset(serverUnique, 0, sizeof(serverUnique)); switch ( method ) { case 0: @@ -460,46 +461,14 @@ long cm_UpdateVolumeLocation(struct cm_cell *cellp, cm_user_t *userp, cm_req_t * serverNumber[j] = uvldbEntry.serverNumber[i].time_low; j++; } else { - afs_uint32 * addrp, nentries, code, unique; - bulkaddrs addrs; - ListAddrByAttributes attrs; - afsUUID uuid; - - memset(&attrs, 0, sizeof(attrs)); - attrs.Mask = VLADDR_UUID; - attrs.uuid = uvldbEntry.serverNumber[i]; - memset(&uuid, 0, sizeof(uuid)); - memset(&addrs, 0, sizeof(addrs)); - - do { - code = cm_ConnByMServers(cellp->vlServersp, FALSE, userp, reqp, &connp); - if (code) - continue; - - rxconnp = cm_GetRxConn(connp); - code = VL_GetAddrsU(rxconnp, &attrs, &uuid, &unique, &nentries, &addrs); - rx_PutConnection(rxconnp); - } while (cm_Analyze(connp, userp, reqp, NULL, cellp, 0, NULL, NULL, &cellp->vlServersp, NULL, code)); - - if ( code ) { - code = cm_MapVLRPCError(code, reqp); - osi_Log2(afsd_logp, "CALL VL_GetAddrsU serverNumber %u FAILURE, code 0x%x", - i, code); - continue; - } - osi_Log1(afsd_logp, "CALL VL_GetAddrsU serverNumber %u SUCCESS", i); - - addrp = addrs.bulkaddrs_val; - for (k = 0; k < nentries && j < NMAXNSERVERS; j++, k++) { - serverFlags[j] = uvldbEntry.serverFlags[i]; - serverNumber[j] = addrp[k]; - serverUUID[j] = uuid; - } - - xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs); - - if (nentries == 0) - code = CM_ERROR_INVAL; + code = cm_GetAddrsU(cellp, userp, reqp, + &uvldbEntry.serverNumber[i], + uvldbEntry.serverUnique[i], + uvldbEntry.serverFlags[i], &j, + serverFlags, serverNumber, + serverUUID, serverUnique); + if (code == CM_ERROR_RETRY) + continue; } } nServers = j; /* update the server count */ -- 2.39.5