static void setup_reply(struct nbd_reply* rep, struct nbd_request* req) {
rep->magic = htonl(NBD_REPLY_MAGIC);
rep->error = 0;
- memcpy(&(rep->handle), &(req->handle), sizeof(req->handle));
+ memcpy(&(rep->cookie), &(req->cookie), sizeof(req->cookie));
}
static void log_reply(CLIENT *client, struct nbd_reply *prply) {
rep.magic = htonl(NBD_STRUCTURED_REPLY_MAGIC);
rep.flags = htons(flags);
rep.type = htons(type);
- memcpy(&(rep.handle), req->handle, sizeof(rep.handle));
+ memcpy(&(rep.cookie), req->cookie, sizeof(rep.cookie));
rep.paylen = htonl(length);
pthread_mutex_lock(&(client->lock));
socket_write(client, &rep, sizeof rep);
rep.magic = htonl(NBD_STRUCTURED_REPLY_MAGIC);
rep.flags = htons(flags);
rep.type = htons(type);
- memcpy(&(rep.handle), req->handle, sizeof(rep.handle));
+ memcpy(&(rep.cookie), req->cookie, sizeof(rep.cookie));
rep.paylen = htonl(length);
va_start(ap, bufcount);
pthread_mutex_lock(&(client->lock));
req.magic = htonl(NBD_TRACELOG_MAGIC);
req.type = htonl(NBD_TRACELOG_SET_DATALOG);
- memset(req.handle, 0, sizeof(req.handle));
+ memset(req.cookie, 0, sizeof(req.cookie));
req.from = htonll(NBD_TRACELOG_FROM_MAGIC);
req.len = htonl(TRUE);
struct nbd_request req;
struct nbd_reply rep;
uint32_t magic;
- uint64_t handle;
+ uint64_t cookie;
uint32_t error;
uint32_t command;
uint32_t len;
switch (magic) {
case NBD_REQUEST_MAGIC:
doread(readfd, sizeof(magic)+(char *)(&req), sizeof(struct nbd_request)-sizeof(magic));
- handle = ntohll(*((long long int *)(req.handle)));
+ cookie = ntohll(*((long long int *)(req.cookie)));
offset = ntohll(req.from);
len = ntohl(req.len);
command = ntohl(req.type);
ctext = getcommandname(command & NBD_CMD_MASK_COMMAND);
printf("> H=%016llx C=0x%08x (%20s+%4s) O=%016llx L=%08x\n",
- (long long unsigned int) handle,
+ (long long unsigned int) cookie,
command,
ctext,
(command & NBD_CMD_FLAG_FUA)?"FUA":"NONE",
break;
case NBD_REPLY_MAGIC:
doread(readfd, sizeof(magic)+(char *)(&rep), sizeof(struct nbd_reply)-sizeof(magic));
- handle = ntohll(*((long long int *)(rep.handle)));
+ cookie = ntohll(*((long long int *)(rep.cookie)));
error = ntohl(rep.error);
printf("< H=%016llx E=0x%08x\n",
- (long long unsigned int) handle,
+ (long long unsigned int) cookie,
error);
break;
case NBD_TRACELOG_MAGIC:
doread(readfd, sizeof(magic)+(char *)(&req), sizeof(struct nbd_request)-sizeof(magic));
- handle = ntohll(*((long long int *)(req.handle)));
+ cookie = ntohll(*((long long int *)(req.cookie)));
offset = ntohll(req.from);
len = ntohl(req.len);
command = ntohl(req.type);
struct nbd_request req;
struct nbd_reply rep;
uint32_t magic;
- uint64_t handle;
+ uint64_t cookie;
uint32_t error;
uint32_t command;
uint32_t len;
switch (magic) {
case NBD_REQUEST_MAGIC:
doread(logfd, sizeof(magic)+(char *)(&req), sizeof(struct nbd_request)-sizeof(magic));
- handle = ntohll(*((long long int *)(req.handle)));
+ cookie = ntohll(*((long long int *)(req.cookie)));
offset = ntohll(req.from);
len = ntohl(req.len);
command = ntohl(req.type);
if (g_verbose >= VERBOSE_NORMAL) {
printf("> H=%016llx C=0x%08x (%13s+%4s) O=%016llx L=%08x\n",
- (long long unsigned int) handle,
+ (long long unsigned int) cookie,
command,
ctext,
(command & NBD_CMD_FLAG_FUA)?"FUA":"NONE",
case NBD_REPLY_MAGIC:
doread(logfd, sizeof(magic)+(char *)(&rep), sizeof(struct nbd_reply)-sizeof(magic));
- handle = ntohll(*((long long int *)(rep.handle)));
+ cookie = ntohll(*((long long int *)(rep.cookie)));
error = ntohl(rep.error);
if (g_verbose >= VERBOSE_NORMAL) {
printf("< H=%016llx E=0x%08x\n",
- (long long unsigned int) handle,
+ (long long unsigned int) cookie,
error);
}
break;
case NBD_TRACELOG_MAGIC:
doread(logfd, sizeof(magic)+(char *)(&req), sizeof(struct nbd_request)-sizeof(magic));
- handle = ntohll(*((long long int *)(req.handle)));
+ cookie = ntohll(*((long long int *)(req.cookie)));
offset = ntohll(req.from);
len = ntohl(req.len);
command = ntohl(req.type);
struct reqcontext {
uint64_t seq;
- char orighandle[8];
+ char origcookie[8];
struct nbd_request req;
struct reqcontext *next;
struct reqcontext *prev;
case CONNECTION_CLOSE_PROPERLY:
req.magic = htonl(NBD_REQUEST_MAGIC);
req.type = htonl(NBD_CMD_DISC);
- memcpy(&(req.handle), &(counter), sizeof(counter));
+ memcpy(&(req.cookie), &(counter), sizeof(counter));
counter++;
req.from = 0;
req.len = 0;
return 0;
}
-int read_packet_check_header(int sock, size_t datasize, long long int curhandle)
+int read_packet_check_header(int sock, size_t datasize, long long int curcookie)
{
struct nbd_reply rep;
int retval = 0;
rep.error = ntohl(rep.error);
if (rep.magic != NBD_REPLY_MAGIC) {
snprintf(errstr, errstr_len,
- "Received package with incorrect reply_magic. Index of sent packages is %lld (0x%llX), received handle is %lld (0x%llX). Received magic 0x%lX, expected 0x%lX",
- (long long int)curhandle,
- (long long unsigned int)curhandle,
- (long long int)*((u64 *) rep.handle),
- (long long unsigned int)*((u64 *) rep.handle),
+ "Received package with incorrect reply_magic. Index of sent packages is %lld (0x%llX), received cookie is %lld (0x%llX). Received magic 0x%lX, expected 0x%lX",
+ (long long int)curcookie,
+ (long long unsigned int)curcookie,
+ (long long int)*((u64 *) rep.cookie),
+ (long long unsigned int)*((u64 *) rep.cookie),
(long unsigned int)rep.magic,
(long unsigned int)NBD_REPLY_MAGIC);
retval = -1;
}
if (rep.error) {
snprintf(errstr, errstr_len,
- "Received error from server: %ld (0x%lX). Handle is %lld (0x%llX).",
+ "Received error from server: %ld (0x%lX). Cookie is %lld (0x%llX).",
(long int)rep.error, (long unsigned int)rep.error,
- (long long int)(*((u64 *) rep.handle)),
- (long long unsigned int)*((u64 *) rep.handle));
+ (long long int)(*((u64 *) rep.cookie)),
+ (long long unsigned int)*((u64 *) rep.cookie));
retval = -2;
goto end;
}
req.magic = htonl(NBD_REQUEST_MAGIC);
req.type = htonl(NBD_CMD_READ);
req.len = htonl(1024 * 1024);
- memcpy(&(req.handle), &i, sizeof(i));
+ memcpy(&(req.cookie), &i, sizeof(i));
req.from = htonll(i);
WRITE_ALL_ERR_RT(sock, &req, sizeof(req), err, -1,
"Could not write request: %s", strerror(errno));
if (sendfua)
req.type =
htonl(NBD_CMD_WRITE | NBD_CMD_FLAG_FUA);
- memcpy(&(req.handle), &i, sizeof(i));
+ memcpy(&(req.cookie), &i, sizeof(i));
req.from = htonll(i);
if (write_all(sock, &req, sizeof(req)) < 0) {
retval = -1;
if (sendflush) {
long long int j = i ^ (1LL << 63);
req.type = htonl(NBD_CMD_FLUSH);
- memcpy(&(req.handle), &j, sizeof(j));
+ memcpy(&(req.cookie), &j, sizeof(j));
req.from = 0;
req.len = 0;
if (write_all(sock, &req, sizeof(req)) < 0) {
/*
* fill 512 byte buffer 'buf' with a hashed selection of interesting data based
- * only on handle and blknum. The first word is blknum, and the second handle, for ease
- * of understanding. Things with handle 0 are blank.
+ * only on cookie and blknum. The first word is blknum, and the second cookie, for ease
+ * of understanding. Things with cookie 0 are blank.
*/
static inline void makebuf(char *buf, uint64_t seq, uint64_t blknum)
{
#endif
}
-/* return an unused handle */
-uint64_t getrandomhandle(GHashTable * phash)
+/* return an unused cookie */
+uint64_t getrandomcookie(GHashTable * phash)
{
- uint64_t handle = 0;
+ uint64_t cookie = 0;
int i;
do {
/* RAND_MAX may be as low as 2^15 */
for (i = 1; i <= 5; i++)
- handle ^= random() ^ (handle << 15);
- } while (g_hash_table_lookup(phash, &handle));
- return handle;
+ cookie ^= random() ^ (cookie << 15);
+ } while (g_hash_table_lookup(phash, &cookie));
+ return cookie;
}
int integrity_test(char *name, int sock, char close_sock, int testflags)
struct rclist inflight = { NULL, NULL, 0 };
struct chunklist txbuf = { NULL, NULL, 0 };
- GHashTable *handlehash = g_hash_table_new(g_int64_hash, g_int64_equal);
+ GHashTable *cookiehash = g_hash_table_new(g_int64_hash, g_int64_equal);
size = 0;
if ((sock =
"Could not read transaction log: %s",
strerror(errno));
prc->req.magic = htonl(NBD_REQUEST_MAGIC);
- memcpy(prc->orighandle, prc->req.handle, 8);
+ memcpy(prc->origcookie, prc->req.cookie, 8);
prc->seq = seq++;
if ((ntohl(prc->req.type) &
NBD_CMD_MASK_COMMAND) == NBD_CMD_DISC) {
rclist_addtail(&inflight, prc);
dumpcommand("Sending command", prc->req.type);
- /* we rewrite the handle as they otherwise may not be unique */
- *((uint64_t *) (prc->req.handle)) =
- getrandomhandle(handlehash);
- g_hash_table_insert(handlehash, prc->req.handle,
+ /* we rewrite the cookie as they otherwise may not be unique */
+ *((uint64_t *) (prc->req.cookie)) =
+ getrandomcookie(cookiehash);
+ g_hash_table_insert(cookiehash, prc->req.cookie,
prc);
addbuffer(&txbuf, &(prc->req),
sizeof(struct nbd_request));
goto err_open;
}
- uint64_t handle;
- memcpy(&handle, rep.handle, 8);
- prc = g_hash_table_lookup(handlehash, &handle);
+ uint64_t cookie;
+ memcpy(&cookie, rep.cookie, 8);
+ prc = g_hash_table_lookup(cookiehash, &cookie);
if (!prc) {
snprintf(errstr, errstr_len,
- "Unrecognised handle in reply: 0x%llX",
+ "Unrecognised cookie in reply: 0x%llX",
*(long long unsigned int *)(rep.
- handle));
+ cookie));
goto err_open;
}
- if (!g_hash_table_remove(handlehash, &handle)) {
+ if (!g_hash_table_remove(cookiehash, &cookie)) {
snprintf(errstr, errstr_len,
- "Could not remove handle from hash: 0x%llX",
+ "Could not remove cookie from hash: 0x%llX",
*(long long unsigned int *)(rep.
- handle));
+ cookie));
goto err_open;
}
if (*errstr)
g_warning("%s", errstr);
- g_hash_table_destroy(handlehash);
+ g_hash_table_destroy(cookiehash);
return retval;
}