xref: /openbmc/qemu/nbd/nbd-internal.h (revision ae6d91a7)
1798bfe00SFam Zheng /*
2798bfe00SFam Zheng  * NBD Internal Declarations
3798bfe00SFam Zheng  *
4d95ffb6fSEric Blake  * Copyright Red Hat
5798bfe00SFam Zheng  *
6798bfe00SFam Zheng  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7798bfe00SFam Zheng  * See the COPYING file in the top-level directory.
8798bfe00SFam Zheng  */
9798bfe00SFam Zheng 
10798bfe00SFam Zheng #ifndef NBD_INTERNAL_H
11798bfe00SFam Zheng #define NBD_INTERNAL_H
12798bfe00SFam Zheng #include "block/nbd.h"
13798bfe00SFam Zheng #include "sysemu/block-backend.h"
14f95910feSDaniel P. Berrange #include "io/channel-tls.h"
15798bfe00SFam Zheng 
161c778ef7SDaniel P. Berrange #include "qemu/iov.h"
17798bfe00SFam Zheng 
18798bfe00SFam Zheng #ifndef _WIN32
19798bfe00SFam Zheng #include <sys/ioctl.h>
20798bfe00SFam Zheng #endif
21ded5d78cSThomas Huth #ifdef HAVE_SYS_IOCCOM_H
22798bfe00SFam Zheng #include <sys/ioccom.h>
23798bfe00SFam Zheng #endif
24798bfe00SFam Zheng 
25798bfe00SFam Zheng #ifdef __linux__
26798bfe00SFam Zheng #include <linux/fs.h>
27798bfe00SFam Zheng #endif
28798bfe00SFam Zheng 
2958369e22SPaolo Bonzini #include "qemu/bswap.h"
30798bfe00SFam Zheng 
31798bfe00SFam Zheng /* This is all part of the "official" NBD API.
32798bfe00SFam Zheng  *
33798bfe00SFam Zheng  * The most up-to-date documentation is available at:
34b626b51aSEric Blake  * https://github.com/yoe/nbd/blob/master/doc/proto.md
35798bfe00SFam Zheng  */
36798bfe00SFam Zheng 
37*c8720ca0SEric Blake /* Size of all compact NBD_CMD_*, without payload */
38b626b51aSEric Blake #define NBD_REQUEST_SIZE            (4 + 2 + 2 + 8 + 8 + 4)
39*c8720ca0SEric Blake /* Size of all extended NBD_CMD_*, without payload */
40*c8720ca0SEric Blake #define NBD_EXTENDED_REQUEST_SIZE   (4 + 2 + 2 + 8 + 8 + 8)
41*c8720ca0SEric Blake 
428ecaeae8SEric Blake /* Size of all NBD_REP_* sent in answer to most NBD_OPT_*, without payload */
43798bfe00SFam Zheng #define NBD_REPLY_SIZE              (4 + 4 + 8)
445f66d060SEric Blake /* Size of reply to NBD_OPT_EXPORT_NAME */
455f66d060SEric Blake #define NBD_REPLY_EXPORT_NAME_SIZE  (8 + 2 + 124)
465f66d060SEric Blake /* Size of oldstyle negotiation */
475f66d060SEric Blake #define NBD_OLDSTYLE_NEGOTIATE_SIZE (8 + 8 + 8 + 4 + 124)
488ecaeae8SEric Blake 
49ef2e35fcSEric Blake #define NBD_INIT_MAGIC              0x4e42444d41474943LL /* ASCII "NBDMAGIC" */
50ef2e35fcSEric Blake #define NBD_OPTS_MAGIC              0x49484156454F5054LL /* ASCII "IHAVEOPT" */
51798bfe00SFam Zheng #define NBD_CLIENT_MAGIC            0x0000420281861253LL
52c8a3a1b6SEric Blake #define NBD_REP_MAGIC               0x0003e889045565a9LL
53798bfe00SFam Zheng 
54798bfe00SFam Zheng #define NBD_SET_SOCK                _IO(0xab, 0)
55798bfe00SFam Zheng #define NBD_SET_BLKSIZE             _IO(0xab, 1)
56798bfe00SFam Zheng #define NBD_SET_SIZE                _IO(0xab, 2)
57798bfe00SFam Zheng #define NBD_DO_IT                   _IO(0xab, 3)
58798bfe00SFam Zheng #define NBD_CLEAR_SOCK              _IO(0xab, 4)
59798bfe00SFam Zheng #define NBD_CLEAR_QUE               _IO(0xab, 5)
60798bfe00SFam Zheng #define NBD_PRINT_DEBUG             _IO(0xab, 6)
61798bfe00SFam Zheng #define NBD_SET_SIZE_BLOCKS         _IO(0xab, 7)
62798bfe00SFam Zheng #define NBD_DISCONNECT              _IO(0xab, 8)
63798bfe00SFam Zheng #define NBD_SET_TIMEOUT             _IO(0xab, 9)
64798bfe00SFam Zheng #define NBD_SET_FLAGS               _IO(0xab, 10)
65798bfe00SFam Zheng 
66d1fdf257SVladimir Sementsov-Ogievskiy /* nbd_write
67f5d406feSVladimir Sementsov-Ogievskiy  * Writes @size bytes to @ioc. Returns 0 on success.
68f5d406feSVladimir Sementsov-Ogievskiy  */
nbd_write(QIOChannel * ioc,const void * buffer,size_t size,Error ** errp)69d1fdf257SVladimir Sementsov-Ogievskiy static inline int nbd_write(QIOChannel *ioc, const void *buffer, size_t size,
70e44ed99dSVladimir Sementsov-Ogievskiy                             Error **errp)
71798bfe00SFam Zheng {
72030fa7f6SEric Blake     return qio_channel_write_all(ioc, buffer, size, errp) < 0 ? -EIO : 0;
73798bfe00SFam Zheng }
74798bfe00SFam Zheng 
7544298024SVladimir Sementsov-Ogievskiy int nbd_drop(QIOChannel *ioc, size_t size, Error **errp);
7644298024SVladimir Sementsov-Ogievskiy 
77798bfe00SFam Zheng #endif
78