buse.c: conditional defines to work with older nbd versions

This commit is contained in:
Pete Nelson 2013-06-27 13:27:10 -04:00
parent a1e8b08807
commit 36a70c004e
1 changed files with 6 additions and 0 deletions

6
buse.c
View File

@ -88,9 +88,11 @@ int buse_main(const char* dev_file, const struct buse_operations *aop, void *use
if(ioctl(nbd, NBD_SET_SOCK, sk) == -1){
fprintf(stderr, "ioctl(nbd, NBD_SET_SOCK, sk) failed.[%s]\n", strerror(errno));
}
#if defined NBD_SET_FLAGS && defined NBD_FLAG_SEND_TRIM
else if(ioctl(nbd, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM) == -1){
fprintf(stderr, "ioctl(nbd, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM) failed.[%s]\n", strerror(errno));
}
#endif
else{
err = ioctl(nbd, NBD_DO_IT);
fprintf(stderr, "nbd device terminated with code %d\n", err);
@ -153,14 +155,18 @@ int buse_main(const char* dev_file, const struct buse_operations *aop, void *use
/* Handle a disconnect request. */
aop->disc(userdata);
return 0;
#if defined NBD_CMD_FLUSH
case NBD_CMD_FLUSH:
reply.error = aop->flush(userdata);
write_all(sk, (char*)&reply, sizeof(struct nbd_reply));
break;
#endif
#if defined NBD_CMD_TRIM
case NBD_CMD_TRIM:
reply.error = aop->trim(from, len, userdata);
write_all(sk, (char*)&reply, sizeof(struct nbd_reply));
break;
#endif
default:
assert(0);
}