Implement support for flush, fua and rotational.
[nbd.git] / nbd-client.c
index 0fc9c34..78e62f9 100644 (file)
@@ -150,7 +150,7 @@ void negotiate(int sock, u64 *rsize64, u32 *flags, char* name) {
                if(read(sock, &tmp, sizeof(uint16_t)) < 0) {
                        err("Failed reading flags: %m");
                }
-               *flags = ((u32)ntohs(tmp)) << 16;
+               *flags = ((u32)ntohs(tmp));
 
                /* reserved for future use*/
                if (write(sock, &reserved, sizeof(reserved)) < 0)
@@ -240,6 +240,9 @@ void setsizes(int nbd, u64 size64, int blocksize, u32 flags) {
 
        ioctl(nbd, NBD_CLEAR_SOCK);
 
+       /* ignore error as kernel may not support */
+       ioctl(nbd, NBD_SET_FLAGS, (unsigned long) flags);
+
        if (ioctl(nbd, BLKROSET, (unsigned long) &read_only) < 0)
                err("Unable to set read-only attribute for device");
 }