#include <sys/types.h>
#include <string.h>
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
#ifdef AFS_NT40_ENV
#include <fcntl.h>
#include <io.h>
#include <winsock2.h>
+#include <WINNT/afsreg.h>
#else
#include <sys/time.h>
#include <sys/file.h>
#include <afs/ihandle.h>
#include <afs/vnode.h>
#include <afs/volume.h>
+#include <afs/com_err.h>
#include "dump.h"
#include "lockdata.h"
#ifdef AFS_AIX32_ENV
#include <signal.h>
#endif
+#include "volser_internal.h"
#include "volser_prototypes.h"
#include "vsutils_prototypes.h"
#include "lockprocs_prototypes.h"
static void
qInit(struct tqHead *ahead)
{
- memset((char *)ahead, 0, sizeof(struct tqHead));
+ memset(ahead, 0, sizeof(struct tqHead));
return;
}
/*
- * Parse a server name/address and return the address in HOST BYTE order
+ * Parse a server dotted address and return the address in network byte order
*/
afs_int32
-GetServer(char *aname)
+GetServerNoresolve(char *aname)
{
- register struct hostent *th;
- afs_int32 addr;
int b1, b2, b3, b4;
- register afs_int32 code;
- char hostname[MAXHOSTCHARS];
+ afs_int32 addr;
+ afs_int32 code;
code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
if (code == 4) {
addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
- addr = ntohl(addr); /* convert to host order */
- } else {
+ addr = htonl(addr); /* convert to network byte order */
+ return addr;
+ } else
+ return 0;
+}
+/*
+ * Parse a server name/address and return the address in network byte order
+ */
+afs_int32
+GetServer(char *aname)
+{
+ register struct hostent *th;
+ afs_int32 addr; /* in network byte order */
+ register afs_int32 code;
+ char hostname[MAXHOSTCHARS];
+
+ if ((addr = GetServerNoresolve(aname)) == 0) {
th = gethostbyname(aname);
if (!th)
return 0;
code = gethostname(hostname, MAXHOSTCHARS);
if (code)
return 0;
- th = gethostbyname(hostname); /* returns host byte order */
+ th = gethostbyname(hostname);
if (!th)
return 0;
memcpy(&addr, th->h_addr, sizeof(addr));
FD_SET((intptr_t)(ufd->handle), &in);
/* don't timeout if read blocks */
#if defined(AFS_PTHREAD_ENV)
- select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
+ select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
#else
IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
#endif
#endif
error = USD_READ(ufd, buffer, blksize, &nbytes);
if (error) {
- fprintf(STDERR, "File system read failed\n");
+ fprintf(STDERR, "File system read failed: %s\n",
+ afs_error_message(error));
break;
}
if (nbytes == 0) {
code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
}
if (code) {
- fprintf(STDERR, "Could not access file '%s'\n", filename);
+ fprintf(STDERR, "Could not access file '%s': %s\n", filename,
+ afs_error_message(code));
error = VOLSERBADOP;
goto wfail;
}
FD_SET((intptr_t)(ufd->handle), &out);
/* don't timeout if write blocks */
#if defined(AFS_PTHREAD_ENV)
- select(((int)(ufd->handle)) + 1, &out, 0, 0, 0);
+ select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
#else
IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
#endif
error =
USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
if (error) {
- fprintf(STDERR, "File system write failed\n");
+ fprintf(STDERR, "File system write failed: %s\n",
+ afs_error_message(error));
ERROR_EXIT(-1);
}
}
code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
}
if (code) {
- fprintf(STDERR, "Could not create file '%s'\n", filename);
+ fprintf(STDERR, "Could not create file '%s': %s\n", filename,
+ afs_error_message(code));
ERROR_EXIT(VOLSERBADOP);
}
}
t = pntr->creationDate;
fprintf(STDOUT, " Creation %s",
ctime(&t));
-#ifdef FULL_LISTVOL_SWITCH
t = pntr->copyDate;
fprintf(STDOUT, " Copy %s",
ctime(&t));
if (t)
fprintf(STDOUT, " Last Access %s",
ctime(&t));
-#endif
+
t = pntr->updateDate;
if (!t)
fprintf(STDOUT, " Last Update Never\n");
t = a_xInfoP->creationDate;
fprintf(STDOUT, " Creation %s",
ctime(&t));
-#ifdef FULL_LISTVOL_SWITCH
+
t = a_xInfoP->copyDate;
fprintf(STDOUT, " Copy %s",
ctime(&t));
if (t)
fprintf(STDOUT, " Last Access %s",
ctime(&t));
-#endif
+
t = a_xInfoP->updateDate;
if (!t)
fprintf(STDOUT, " Last Update Never\n");
} /*Default listing */
} /*XDisplayFormat */
-#ifdef FULL_LISTVOL_SWITCH
/*------------------------------------------------------------------------
* PRIVATE XDisplayFormat2
*
} /*Screwed volume */
} /*Default listing */
} /*XDisplayFormat */
-#endif /*FULL_LISTVOL_SWITCH*/
-#ifdef FULL_LISTVOL_SWITCH
static void
DisplayFormat2(long server, long partition, volintInfo *pntr)
{
}
return;
}
-#endif /* FULL_LISTVOL_SWITCH */
static void
DisplayVolumes(afs_int32 server, afs_int32 part, volintInfo *pntr,
}
} /*XDisplayVolumes */
-#ifdef FULL_LISTVOL_SWITCH
+
/*------------------------------------------------------------------------
* PRIVATE XDisplayVolumes2
*
}
} /*XDisplayVolumes2 */
-#endif /* FULL_LISTVOL_SWITCH */
/* set <server> and <part> to the correct values depending on
foundserv = 1;
if (wantExtendedInfo)
XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
- else
-#ifdef FULL_LISTVOL_SWITCH
- if (as->parms[2].items) {
+ else if (as->parms[2].items) {
DisplayFormat2(aserver, apart, pntr);
EnumerateEntry(&entry);
} else
-#endif /* FULL_LISTVOL_SWITCH */
VolumeStats_int(pntr, &entry, aserver, apart, voltype);
if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
as->parms[0].items->data, pname,
(unsigned long)count);
if (wantExtendedInfo) {
-#ifdef FULL_LISTVOL_SWITCH
if (as->parms[6].items)
XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
count, int32list, fast, quiet);
else
-#endif /* FULL_LISTVOL_SWITCH */
- XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
+ XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
count, int32list, fast, quiet);
if (xInfoP)
free(xInfoP);
xInfoP = (volintXInfo *) 0;
} else {
-#ifdef FULL_LISTVOL_SWITCH
if (as->parms[6].items)
DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
count);
else
-#endif /* FULL_LISTVOL_SWITCH */
DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
count, int32list, fast, quiet);
if (pntr)
afs_int32 ip1, ip2, vcode;
int remove = 0;
- ip1 = GetServer(as->parms[0].items->data);
+ if (noresolve)
+ ip1 = GetServerNoresolve(as->parms[0].items->data);
+ else
+ ip1 = GetServer(as->parms[0].items->data);
if (!ip1) {
fprintf(STDERR, "vos: invalid host address\n");
return (EINVAL);
}
if (as->parms[1].items) {
- ip2 = GetServer(as->parms[1].items->data);
+ if (noresolve)
+ ip2 = GetServerNoresolve(as->parms[1].items->data);
+ else
+ ip2 = GetServer(as->parms[1].items->data);
if (!ip2) {
fprintf(STDERR, "vos: invalid host address\n");
return (EINVAL);
ip1 = 0xffffffff;
}
- vcode = ubik_Call_New(VL_ChangeAddr, cstruct, 0, ntohl(ip1), ntohl(ip2));
+ vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
if (vcode) {
+ char hoststr1[16], hoststr2[16];
if (remove) {
+ afs_inet_ntoa_r(ip2, hoststr2);
fprintf(STDERR, "Could not remove server %s from the VLDB\n",
- as->parms[0].items->data);
+ hoststr2);
if (vcode == VL_NOENT) {
fprintf(STDERR,
"vlserver does not support the remove flag or ");
}
} else {
+ afs_inet_ntoa_r(ip1, hoststr1);
+ afs_inet_ntoa_r(ip2, hoststr2);
fprintf(STDERR, "Could not change server %s to server %s\n",
- as->parms[0].items->data, as->parms[1].items->data);
+ hoststr1, hoststr2);
}
PrintError("", vcode);
return (vcode);
print_addrs(const bulkaddrs * addrs, afsUUID * m_uuid, int nentries,
int print)
{
- afs_int32 vcode;
+ afs_int32 vcode, m_uniq=0;
afs_int32 i, j;
- struct VLCallBack vlcb;
afs_int32 *addrp;
bulkaddrs m_addrs;
ListAddrByAttributes m_attrs;
m_addrs.bulkaddrs_len = 0;
vcode =
ubik_VL_GetAddrsU(cstruct, 0, &m_attrs, m_uuid,
- (afs_int32 *)&vlcb, &m_nentries, &m_addrs);
+ &m_uniq, &m_nentries,
+ &m_addrs);
if (vcode) {
fprintf(STDERR,
"vos: could not list the multi-homed server addresses\n");
static int
ListAddrs(register struct cmd_syndesc *as, void *arock)
{
- afs_int32 vcode;
+ afs_int32 vcode, m_uniq=0;
afs_int32 i, printuuid = 0;
struct VLCallBack vlcb;
afs_int32 nentries;
m_addrs.bulkaddrs_len = 0;
vcode =
- ubik_Call_New(VL_GetAddrs, cstruct, 0, 0, 0, &vlcb, &nentries,
- &m_addrs);
+ ubik_VL_GetAddrs(cstruct, UBIK_CALL_NEW, 0, 0, &vlcb, &nentries,
+ &m_addrs);
if (vcode) {
fprintf(STDERR, "vos: could not list the server addresses\n");
PrintError("", vcode);
m_attrs.index = i;
vcode =
- ubik_Call_New(VL_GetAddrsU, cstruct, 0, &m_attrs, &m_uuid,
- &vlcb, &m_nentries, &m_addrs);
+ ubik_VL_GetAddrsU(cstruct, UBIK_CALL_NEW, &m_attrs, &m_uuid,
+ &m_uniq, &m_nentries, &m_addrs);
if (vcode == VL_NOENT) {
if (m_attrs.Mask == VLADDR_UUID) {
return 0;
}
+
+static int
+SetAddrs(register struct cmd_syndesc *as, void *arock)
+{
+ afs_int32 vcode;
+ bulkaddrs m_addrs;
+ afsUUID askuuid;
+ afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
+
+ memset(&m_addrs, 0, sizeof(bulkaddrs));
+ memset(&askuuid, 0, sizeof(afsUUID));
+ if (as->parms[0].items) {
+ /* -uuid */
+ if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
+ fprintf(STDERR, "vos: invalid UUID '%s'\n",
+ as->parms[0].items->data);
+ exit(-1);
+ }
+ }
+ if (as->parms[1].items) {
+ /* -host */
+ struct cmd_item *ti;
+ afs_int32 saddr;
+ int i = 0;
+
+ for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
+
+ if (noresolve)
+ saddr = GetServerNoresolve(ti->data);
+ else
+ saddr = GetServer(ti->data);
+
+ if (!saddr) {
+ fprintf(STDERR, "vos: Can't get host info for '%s'\n",
+ ti->data);
+ exit(-1);
+ }
+ /* Convert it to host byte order */
+ FS_HostAddrs_HBO[i] = ntohl(saddr);
+ i++;
+ }
+ m_addrs.bulkaddrs_len = i;
+ m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
+ }
+
+ vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
+
+ if (vcode) {
+ if (vcode == VL_MULTIPADDR) {
+ fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
+ PrintError("", vcode);
+ return vcode;
+ } else if (vcode == RXGEN_OPCODE) {
+ fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
+ PrintError("", vcode);
+ return vcode;
+ }
+ }
+ if (verbose) {
+ fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
+ print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
+ }
+ return 0;
+}
+
static int
LockEntry(register struct cmd_syndesc *as, void *arock)
{
return 0;
}
+static int
+EndTrans(register struct cmd_syndesc *as, void *arock)
+{
+ afs_int32 server, code, tid, rcode;
+ struct rx_connection *aconn;
+
+ server = GetServer(as->parms[0].items->data);
+ if (!server) {
+ fprintf(STDERR, "vos: host '%s' not found in host table\n",
+ as->parms[0].items->data);
+ return EINVAL;
+ }
+
+ code = util_GetInt32(as->parms[1].items->data, &tid);
+ if (code) {
+ fprintf(STDERR, "vos: bad integer specified for transaction ID.\n");
+ return code;
+ }
+
+ aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
+ code = AFSVolEndTrans(aconn, tid, &rcode);
+ if (!code) {
+ code = rcode;
+ }
+
+ if (code) {
+ PrintDiagnostics("endtrans", code);
+ return 1;
+ }
+
+ return 0;
+}
+
int
PrintDiagnostics(char *astring, afs_int32 acode)
{
}
+#ifdef AFS_NT40_ENV
+static DWORD
+win32_enableCrypt(void)
+{
+ HKEY parmKey;
+ DWORD dummyLen;
+ DWORD cryptall = 0;
+ DWORD code;
+
+ /* Look up configuration parameters in Registry */
+ code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
+ 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
+ if (code != ERROR_SUCCESS) {
+ dummyLen = sizeof(cryptall);
+ RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
+ (BYTE *) &cryptall, &dummyLen);
+ }
+ RegCloseKey (parmKey);
+
+ return cryptall;
+}
+#endif /* AFS_NT40_ENV */
+
static int
MyBeforeProc(struct cmd_syndesc *as, void *arock)
{
tcell = as->parms[12].items->data;
if (as->parms[14].items) /* -serverauth specified */
sauth = 1;
- if (as->parms[16].items) /* -crypt specified */
+ if (as->parms[16].items /* -encrypt specified */
+#ifdef AFS_NT40_ENV
+ || win32_enableCrypt()
+#endif /* AFS_NT40_ENV */
+ )
vsu_SetCrypt(1);
if ((code =
vsu_ClientInit((as->parms[13].items != 0), confdir, tcell, sauth,
"generate minimal information");
cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
"list extended volume fields");
-#ifdef FULL_LISTVOL_SWITCH
cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
"machine readable format");
-#endif /* FULL_LISTVOL_SWITCH */
COMMONPARMS;
ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
"list extended volume fields");
-#ifdef FULL_LISTVOL_SWITCH
cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
"machine readable format");
-#endif /* FULL_LISTVOL_SWITCH */
COMMONPARMS;
cmd_CreateAlias(ts, "volinfo");
cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_OPTIONAL, "dump from time");
COMMONPARMS;
+ ts = cmd_CreateSyntax("endtrans", EndTrans, NULL,
+ "end a volserver transaction");
+ cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
+ cmd_AddParm(ts, "-transaction", CMD_SINGLE, 0,
+ "transaction ID");
+ COMMONPARMS;
+
+ ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
+ "set the list of IP address for a given UUID in the VLDB");
+ cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
+ cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
+
+ COMMONPARMS;
code = cmd_Dispatch(argc, argv);
if (rxInitDone) {
/* Shut down the ubik_client and rx connections */