Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cliserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <cliserv.h>
#include <nbd-debug.h>

const u64 cliserv_magic = 0x00420281861253LL;
const u64 opts_magic = 0x49484156454F5054LL;
const u64 rep_magic = 0x3e889045565a9LL;
const uint64_t cliserv_magic = 0x00420281861253LL;
const uint64_t opts_magic = 0x49484156454F5054LL;
const uint64_t rep_magic = 0x3e889045565a9LL;

/**
* Set a socket to blocking or non-blocking
Expand Down Expand Up @@ -99,8 +99,8 @@ uint64_t ntohll(uint64_t a) {
}
#else
uint64_t ntohll(uint64_t a) {
u32 lo = a & 0xffffffff;
u32 hi = a >> 32U;
uint32_t lo = a & 0xffffffff;
uint32_t hi = a >> 32U;
lo = ntohl(lo);
hi = ntohl(hi);
return ((uint64_t) lo) << 32U | hi;
Expand Down
28 changes: 3 additions & 25 deletions cliserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,6 @@
#include <netinet/in.h>
#include <stdlib.h>

#if SIZEOF_UNSIGNED_SHORT_INT==4
typedef unsigned short u32;
#elif SIZEOF_UNSIGNED_INT==4
typedef unsigned int u32;
#elif SIZEOF_UNSIGNED_LONG_INT==4
typedef unsigned long u32;
#else
#error I need at least some 32-bit type
#endif

#if SIZEOF_UNSIGNED_INT==8
typedef unsigned int u64;
#elif SIZEOF_UNSIGNED_LONG_INT==8
typedef unsigned long u64;
#elif SIZEOF_UNSIGNED_LONG_LONG_INT==8
typedef unsigned long long u64;
#else
#error I need at least some 64-bit type
#endif

#define __be32 u32
#define __be64 u64
#include "nbd.h"

#ifndef HAVE_FDATASYNC
Expand All @@ -64,9 +42,9 @@ typedef unsigned long long u64;
#endif
#endif

extern const u64 cliserv_magic;
extern const u64 opts_magic;
extern const u64 rep_magic;
extern const uint64_t cliserv_magic;
extern const uint64_t opts_magic;
extern const uint64_t rep_magic;

#define INIT_PASSWD "NBDMAGIC"

Expand Down
14 changes: 7 additions & 7 deletions nbd-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static struct nl_sock *get_nbd_socket(int *driver_id) {
}

static void netlink_configure(int index, int *sockfds, int num_connects,
u64 size64, int blocksize, uint16_t flags,
uint64_t size64, int blocksize, uint16_t flags,
int timeout, const char *identifier) {
struct nl_sock *socket;
struct nlattr *sock_attr;
Expand Down Expand Up @@ -247,7 +247,7 @@ static void netlink_disconnect(char *nbddev) {
}
#else
static void netlink_configure(int index, int *sockfds, int num_connects,
u64 size64, int blocksize, uint16_t flags,
uint64_t size64, int blocksize, uint16_t flags,
int timeout, const char *identifier)
{
}
Expand Down Expand Up @@ -557,7 +557,7 @@ void send_opt_exportname(int sock, uint16_t *flags, char* name, uint16_t global_
}

void negotiate(int *sockp, uint16_t *flags, uint32_t needed_flags, uint32_t client_flags, uint32_t do_opts) {
u64 magic;
uint64_t magic;
uint16_t tmp;
uint16_t global_flags;
char buf[256] = "\0\0\0\0\0\0\0\0\0";
Expand Down Expand Up @@ -791,22 +791,22 @@ bool get_from_config() {
return retval;
}

void setsizes(int nbd, u64 size64, int blocksize, u32 flags) {
void setsizes(int nbd, uint64_t size64, int blocksize, uint32_t flags) {
unsigned long size;
int read_only = (flags & NBD_FLAG_READ_ONLY) ? 1 : 0;

if (size64>>12 > (uint64_t)~0UL)
err("Device too large.\n");
else {
int tmp_blocksize = 4096;
if (size64 / (u64)blocksize <= (uint64_t)~0UL)
if (size64 / (uint64_t)blocksize <= (uint64_t)~0UL)
tmp_blocksize = blocksize;
if (ioctl(nbd, NBD_SET_BLKSIZE, tmp_blocksize) < 0) {
fprintf(stderr, "Failed to set blocksize %d\n",
tmp_blocksize);
err("Ioctl/1.1a failed: %m\n");
}
size = (unsigned long)(size64 / (u64)tmp_blocksize);
size = (unsigned long)(size64 / (uint64_t)tmp_blocksize);
if (ioctl(nbd, NBD_SET_SIZE_BLOCKS, size) < 0)
err("Ioctl/1.1b failed: %m\n");
if (tmp_blocksize != blocksize) {
Expand All @@ -816,7 +816,7 @@ void setsizes(int nbd, u64 size64, int blocksize, u32 flags) {
err("Ioctl/1.1c failed: %m\n");
}
}
fprintf(stderr, "bs=%d, sz=%" PRIu64 " bytes\n", blocksize, (u64)tmp_blocksize * size);
fprintf(stderr, "bs=%d, sz=%" PRIu64 " bytes\n", blocksize, (uint64_t)tmp_blocksize * size);
}

ioctl(nbd, NBD_CLEAR_SOCK);
Expand Down
14 changes: 7 additions & 7 deletions nbd-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ int expread(READ_CTX *ctx, CLIENT *client) {
len : (size_t)DIFFPAGESIZE-offset;
if (!(client->server->flags & F_COPYONWRITE))
pthread_rwlock_rdlock(&client->export_lock);
if (client->difmap[mapcnt]!=(u32)(-1)) { /* the block is already there */
if (client->difmap[mapcnt]!=(uint32_t)(-1)) { /* the block is already there */
DEBUG("Page %llu is at %lu\n", (unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt]));
char *buf = find_read_buf(ctx);
Expand Down Expand Up @@ -1645,7 +1645,7 @@ int expwrite(off_t a, char *buf, size_t len, CLIENT *client, int fua) {

if (!(client->server->flags & F_COPYONWRITE))
pthread_rwlock_rdlock(&client->export_lock);
if (client->difmap[mapcnt]!=(u32)(-1)) { /* the block is already there */
if (client->difmap[mapcnt]!=(uint32_t)(-1)) { /* the block is already there */
DEBUG("Page %llu is at %lu\n", (unsigned long long)mapcnt,
(unsigned long)(client->difmap[mapcnt])) ;
if (pwrite(client->difffile, buf, wrlen, client->difmap[mapcnt]*DIFFPAGESIZE+offset) != wrlen) goto fail;
Expand Down Expand Up @@ -1945,7 +1945,7 @@ int commit_diff(CLIENT* client, bool lock, int fhandle){
offset = DIFFPAGESIZE*i;
if (lock)
pthread_rwlock_wrlock(&client->export_lock);
if (client->difmap[i] != (u32)-1){
if (client->difmap[i] != (uint32_t)-1){
dirtycount += 1;
DEBUG("flushing dirty page %d, offset %ld\n", i, offset);
if (pread(client->difffile, buf, DIFFPAGESIZE, client->difmap[i]*DIFFPAGESIZE) != DIFFPAGESIZE) {
Expand All @@ -1962,7 +1962,7 @@ int commit_diff(CLIENT* client, bool lock, int fhandle){
}
break;
}
client->difmap[i] = (u32)-1;
client->difmap[i] = (uint32_t)-1;
}
if (lock)
pthread_rwlock_unlock(&client->export_lock);
Expand Down Expand Up @@ -2158,17 +2158,17 @@ bool copyonwrite_prepare(CLIENT* client) {
err("Could not create diff file (%m)");
return false;
}
if ((client->difmap=calloc(client->exportsize/DIFFPAGESIZE,sizeof(u32)))==NULL) {
if ((client->difmap=calloc(client->exportsize/DIFFPAGESIZE,sizeof(uint32_t)))==NULL) {
err("Could not allocate memory");
return false;
}
for (i=0;i<client->exportsize/DIFFPAGESIZE;i++) client->difmap[i]=(u32)-1;
for (i=0;i<client->exportsize/DIFFPAGESIZE;i++) client->difmap[i]=(uint32_t)-1;

return true;
}

void send_export_info(CLIENT* client, SERVER* server, bool maybe_zeroes) {
uint64_t size_host = htonll((u64)(client->exportsize));
uint64_t size_host = htonll((uint64_t)(client->exportsize));
uint16_t flags = NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_WRITE_ZEROES;

socket_write(client, &size_host, 8);
Expand Down
2 changes: 1 addition & 1 deletion nbdsrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ SERVER* dup_serve(const SERVER *const s) {

uint64_t size_autodetect(int fhandle) {
off_t es;
u64 bytes __attribute__((unused));
uint64_t bytes __attribute__((unused));
struct stat stat_buf;
int error;

Expand Down
6 changes: 3 additions & 3 deletions tests/run/nbd-tester-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ int setup_connection_common(int sock, char *name, CONNECTION_TYPE ctype,
int *serverflags, int testflags)
{
char buf[256];
u64 tmp64;
uint64_t tmp64;
uint64_t mymagic = (name ? opts_magic : cliserv_magic);
uint32_t tmp32 = 0;
uint16_t handshakeflags = 0;
Expand Down Expand Up @@ -675,7 +675,7 @@ int setup_inetd_connection(gchar **argv)
int close_connection(int sock, CLOSE_TYPE type)
{
struct nbd_request req;
u64 counter = 0;
uint64_t counter = 0;

switch (type) {
case CONNECTION_CLOSE_PROPERLY:
Expand Down Expand Up @@ -831,7 +831,7 @@ int handshake_test(char *name, int sock, char close_sock, int testflags)
{
int retval = -1;
int serverflags = 0;
u64 tmp64;
uint64_t tmp64;
uint32_t tmp32 = 0;

/* This should work */
Expand Down