1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-1.0+ WITH Linux-syscall-note */ 2607ca46eSDavid Howells /* 3607ca46eSDavid Howells * 1999 Copyright (C) Pavel Machek, pavel@ucw.cz. This code is GPL. 4607ca46eSDavid Howells * 1999/11/04 Copyright (C) 1999 VMware, Inc. (Regis "HPReg" Duchesne) 5607ca46eSDavid Howells * Made nbd_end_request() use the io_request_lock 6607ca46eSDavid Howells * 2001 Copyright (C) Steven Whitehouse 7607ca46eSDavid Howells * New nbd_end_request() for compatibility with new linux block 8607ca46eSDavid Howells * layer code. 9607ca46eSDavid Howells * 2003/06/24 Louis D. Langholtz <ldl@aros.net> 10607ca46eSDavid Howells * Removed unneeded blksize_bits field from nbd_device struct. 11607ca46eSDavid Howells * Cleanup PARANOIA usage & code. 12607ca46eSDavid Howells * 2004/02/19 Paul Clements 13607ca46eSDavid Howells * Removed PARANOIA, plus various cleanup and comments 14daf376a3SEric Blake * 2023 Copyright Red Hat 15*2686eb84SEric Blake * Link to userspace extensions, favor cookie over handle. 16607ca46eSDavid Howells */ 17607ca46eSDavid Howells 18607ca46eSDavid Howells #ifndef _UAPILINUX_NBD_H 19607ca46eSDavid Howells #define _UAPILINUX_NBD_H 20607ca46eSDavid Howells 21607ca46eSDavid Howells #include <linux/types.h> 22607ca46eSDavid Howells 23607ca46eSDavid Howells #define NBD_SET_SOCK _IO( 0xab, 0 ) 24607ca46eSDavid Howells #define NBD_SET_BLKSIZE _IO( 0xab, 1 ) 25607ca46eSDavid Howells #define NBD_SET_SIZE _IO( 0xab, 2 ) 26607ca46eSDavid Howells #define NBD_DO_IT _IO( 0xab, 3 ) 27607ca46eSDavid Howells #define NBD_CLEAR_SOCK _IO( 0xab, 4 ) 28607ca46eSDavid Howells #define NBD_CLEAR_QUE _IO( 0xab, 5 ) 29607ca46eSDavid Howells #define NBD_PRINT_DEBUG _IO( 0xab, 6 ) 30607ca46eSDavid Howells #define NBD_SET_SIZE_BLOCKS _IO( 0xab, 7 ) 31607ca46eSDavid Howells #define NBD_DISCONNECT _IO( 0xab, 8 ) 32607ca46eSDavid Howells #define NBD_SET_TIMEOUT _IO( 0xab, 9 ) 33607ca46eSDavid Howells #define NBD_SET_FLAGS _IO( 0xab, 10) 34607ca46eSDavid Howells 35daf376a3SEric Blake /* 36daf376a3SEric Blake * See also https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md 37daf376a3SEric Blake * for additional userspace extensions not yet utilized in the kernel module. 38daf376a3SEric Blake */ 39daf376a3SEric Blake 40607ca46eSDavid Howells enum { 41607ca46eSDavid Howells NBD_CMD_READ = 0, 42607ca46eSDavid Howells NBD_CMD_WRITE = 1, 43607ca46eSDavid Howells NBD_CMD_DISC = 2, 4475f187abSAlex Bligh NBD_CMD_FLUSH = 3, 45607ca46eSDavid Howells NBD_CMD_TRIM = 4 46daf376a3SEric Blake /* userspace defines additional extension commands */ 47607ca46eSDavid Howells }; 48607ca46eSDavid Howells 49a2c97909SJosef Bacik /* values for flags field, these are server interaction specific. */ 50607ca46eSDavid Howells #define NBD_FLAG_HAS_FLAGS (1 << 0) /* nbd-server supports flags */ 51607ca46eSDavid Howells #define NBD_FLAG_READ_ONLY (1 << 1) /* device is read-only */ 5275f187abSAlex Bligh #define NBD_FLAG_SEND_FLUSH (1 << 2) /* can flush writeback cache */ 53685c9b24SShaun McDowell #define NBD_FLAG_SEND_FUA (1 << 3) /* send FUA (forced unit access) */ 54607ca46eSDavid Howells /* there is a gap here to match userspace */ 55607ca46eSDavid Howells #define NBD_FLAG_SEND_TRIM (1 << 5) /* send trim/discard */ 5663db89eaSJens Axboe #define NBD_FLAG_CAN_MULTI_CONN (1 << 8) /* Server supports multiple connections per export. */ 57607ca46eSDavid Howells 58685c9b24SShaun McDowell /* values for cmd flags in the upper 16 bits of request type */ 59685c9b24SShaun McDowell #define NBD_CMD_FLAG_FUA (1 << 16) /* FUA (forced unit access) op */ 60685c9b24SShaun McDowell 61a2c97909SJosef Bacik /* These are client behavior specific flags. */ 62a2c97909SJosef Bacik #define NBD_CFLAG_DESTROY_ON_DISCONNECT (1 << 0) /* delete the nbd device on 63a2c97909SJosef Bacik disconnect. */ 6408ba91eeSDoron Roberts-Kedes #define NBD_CFLAG_DISCONNECT_ON_CLOSE (1 << 1) /* disconnect the nbd device on 6508ba91eeSDoron Roberts-Kedes * close by last opener. 6608ba91eeSDoron Roberts-Kedes */ 67a2c97909SJosef Bacik 68607ca46eSDavid Howells /* userspace doesn't need the nbd_device structure */ 69607ca46eSDavid Howells 70607ca46eSDavid Howells /* These are sent over the network in the request/reply magic fields */ 71607ca46eSDavid Howells 72607ca46eSDavid Howells #define NBD_REQUEST_MAGIC 0x25609513 73607ca46eSDavid Howells #define NBD_REPLY_MAGIC 0x67446698 74607ca46eSDavid Howells /* Do *not* use magics: 0x12560953 0x96744668. */ 75daf376a3SEric Blake /* magic 0x668e33ef for structured reply not supported by kernel yet */ 76607ca46eSDavid Howells 77607ca46eSDavid Howells /* 78607ca46eSDavid Howells * This is the packet used for communication between client and 79607ca46eSDavid Howells * server. All data are in network byte order. 80607ca46eSDavid Howells */ 81607ca46eSDavid Howells struct nbd_request { 82daf376a3SEric Blake __be32 magic; /* NBD_REQUEST_MAGIC */ 83daf376a3SEric Blake __be32 type; /* See NBD_CMD_* */ 84*2686eb84SEric Blake union { 85*2686eb84SEric Blake __be64 cookie; /* Opaque identifier for request */ 86*2686eb84SEric Blake char handle[8]; /* older spelling of cookie */ 87*2686eb84SEric Blake }; 88607ca46eSDavid Howells __be64 from; 89607ca46eSDavid Howells __be32 len; 90607ca46eSDavid Howells } __attribute__((packed)); 91607ca46eSDavid Howells 92607ca46eSDavid Howells /* 93607ca46eSDavid Howells * This is the reply packet that nbd-server sends back to the client after 94607ca46eSDavid Howells * it has completed an I/O request (or an error occurs). 95607ca46eSDavid Howells */ 96607ca46eSDavid Howells struct nbd_reply { 97daf376a3SEric Blake __be32 magic; /* NBD_REPLY_MAGIC */ 98607ca46eSDavid Howells __be32 error; /* 0 = ok, else error */ 99*2686eb84SEric Blake union { 100*2686eb84SEric Blake __be64 cookie; /* Opaque identifier from request */ 101*2686eb84SEric Blake char handle[8]; /* older spelling of cookie */ 102*2686eb84SEric Blake }; 103607ca46eSDavid Howells }; 104607ca46eSDavid Howells #endif /* _UAPILINUX_NBD_H */ 105