|
Network Block Device @PACKAGE_VERSION@
|
#include "lfs.h"#include <glib.h>#include <stdbool.h>#include <stdint.h>#include <sys/socket.h>#include <sys/types.h>#include "nbd.h"Go to the source code of this file.
Data Structures | |
| struct | SERVER |
| Variables associated with a server. More... | |
| struct | CLIENT |
| Variables associated with a client connection. More... | |
| struct | FILE_INFO |
| Variables associated with an open file. More... | |
Defines | |
| #define | NBDS_ERR g_quark_from_static_string("server-error-quark") |
| Error domain common for all NBD server errors. | |
| #define | msg(prio,...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__) |
| Logging macros. | |
| #define | MY_NAME "nbd_server" |
| #define | F_READONLY 1 |
| Per-export flags: | |
| #define | F_MULTIFILE 2 |
| flag to tell us a file is exported using -m | |
| #define | F_COPYONWRITE 4 |
| flag to tell us a file is exported using copyonwrite | |
| #define | F_AUTOREADONLY 8 |
| flag to tell us a file is set to autoreadonly | |
| #define | F_SPARSE 16 |
| flag to tell us copyronwrite should use a sparse file | |
| #define | F_SDP 32 |
| flag to tell us the export should be done using the Socket Direct Protocol for RDMA | |
| #define | F_SYNC 64 |
| Whether to fsync() after a write. | |
| #define | F_FLUSH 128 |
| Whether server wants FLUSH to be sent by the client. | |
| #define | F_FUA 256 |
| Whether server wants FUA to be sent by the client. | |
| #define | F_ROTATIONAL 512 |
| Whether server wants the client to implement the elevator algorithm. | |
| #define | F_TEMPORARY 1024 |
| Whether the backing file is temporary and should be created then unlinked. | |
| #define | F_TRIM 2048 |
| Whether server wants TRIM (discard) to be sent by the client. | |
| #define | F_FIXED 4096 |
| Client supports fixed new-style protocol (and can thus send us extra options. | |
| #define | F_TREEFILES 8192 |
| flag to tell us a file is exported using -t | |
Enumerations | |
| enum | VIRT_STYLE { VIRT_NONE = 0, VIRT_IPLIT, VIRT_IPHASH, VIRT_CIDR } |
Types of virtuatlization. More... | |
| enum | NBDS_ERRS { NBDS_ERR_CFILE_NOTFOUND, NBDS_ERR_CFILE_MISSING_GENERIC, NBDS_ERR_CFILE_KEY_MISSING, NBDS_ERR_CFILE_VALUE_INVALID, NBDS_ERR_CFILE_VALUE_UNSUPPORTED, NBDS_ERR_CFILE_NO_EXPORTS, NBDS_ERR_CFILE_INCORRECT_PORT, NBDS_ERR_CFILE_DIR_UNKNOWN, NBDS_ERR_CFILE_READDIR_ERR, NBDS_ERR_SO_LINGER, NBDS_ERR_SO_REUSEADDR, NBDS_ERR_SO_KEEPALIVE, NBDS_ERR_GAI, NBDS_ERR_SOCKET, NBDS_ERR_BIND, NBDS_ERR_LISTEN, NBDS_ERR_SYS } |
NBD server error codes. More... | |
Functions | |
| bool | address_matches (const char *mask, const struct sockaddr *addr, GError **err) |
| Check whether a given address matches a given netmask. | |
| uint8_t | getmaskbyte (int masklen) G_GNUC_PURE |
| Gets a byte to allow for address masking. | |
| int | authorized_client (CLIENT *opts) |
| Check whether a client is allowed to connect. | |
| SERVER * | dup_serve (const SERVER *const s) |
| duplicate server | |
| uint64_t | size_autodetect (int fhandle) |
| Detect the size of a file. | |
| int | exptrim (struct nbd_request *req, CLIENT *client) |
| Punch a hole in the backend file (if supported by the current system). | |
| void | myseek (int handle, off_t a) |
| seek to a position in a file, with error handling. | |
| #define F_AUTOREADONLY 8 |
flag to tell us a file is set to autoreadonly
Definition at line 133 of file nbdsrv.h.
Referenced by handle_write(), mainloop(), and setupexport().
| #define F_COPYONWRITE 4 |
flag to tell us a file is exported using copyonwrite
Definition at line 131 of file nbdsrv.h.
Referenced by cmdline(), dump_section(), expflush(), expread(), exptrim(), expwrite(), mainloop(), parse_cfile(), serveconnection(), and setupexport().
| #define F_FIXED 4096 |
| #define F_FLUSH 128 |
Whether server wants FLUSH to be sent by the client.
Definition at line 137 of file nbdsrv.h.
Referenced by parse_cfile(), and send_export_info().
| #define F_FUA 256 |
Whether server wants FUA to be sent by the client.
Definition at line 138 of file nbdsrv.h.
Referenced by parse_cfile(), and send_export_info().
| #define F_MULTIFILE 2 |
flag to tell us a file is exported using -m
Definition at line 130 of file nbdsrv.h.
Referenced by cmdline(), dump_section(), parse_cfile(), and setupexport().
| #define F_READONLY 1 |
Per-export flags:
flag to tell us a file is readonly
Definition at line 129 of file nbdsrv.h.
Referenced by cmdline(), dump_section(), expflush(), exptrim(), get_filepos(), handle_write(), mainloop(), parse_cfile(), send_export_info(), and setupexport().
| #define F_ROTATIONAL 512 |
Whether server wants the client to implement the elevator algorithm.
Definition at line 139 of file nbdsrv.h.
Referenced by parse_cfile(), and send_export_info().
| #define F_SDP 32 |
flag to tell us the export should be done using the Socket Direct Protocol for RDMA
Definition at line 135 of file nbdsrv.h.
Referenced by parse_cfile().
| #define F_SPARSE 16 |
flag to tell us copyronwrite should use a sparse file
Definition at line 134 of file nbdsrv.h.
Referenced by expwrite(), and parse_cfile().
| #define F_SYNC 64 |
Whether to fsync() after a write.
Definition at line 136 of file nbdsrv.h.
Referenced by expwrite(), parse_cfile(), and rawexpwrite().
| #define F_TEMPORARY 1024 |
Whether the backing file is temporary and should be created then unlinked.
Definition at line 140 of file nbdsrv.h.
Referenced by parse_cfile(), and setupexport().
| #define F_TREEFILES 8192 |
flag to tell us a file is exported using -t
Definition at line 143 of file nbdsrv.h.
Referenced by dump_section(), expflush(), exptrim(), get_filepos(), parse_cfile(), rawexpread(), rawexpwrite(), and setupexport().
| #define F_TRIM 2048 |
Whether server wants TRIM (discard) to be sent by the client.
Definition at line 141 of file nbdsrv.h.
Referenced by parse_cfile(), and send_export_info().
| #define msg | ( | prio, | |
| ... | |||
| ) | g_log(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __VA_ARGS__) |
Logging macros.
Definition at line 124 of file nbdsrv.h.
Referenced by authorized_client(), copyonwrite_prepare(), handle_modern_connection(), handle_request(), mainloop(), serveloop(), set_peername(), setup_servers(), setupexport(), and spawn_child().
| #define NBDS_ERR g_quark_from_static_string("server-error-quark") |
Error domain common for all NBD server errors.
Definition at line 88 of file nbdsrv.h.
Referenced by address_matches(), do_cfile_dir(), dosockopts(), main(), open_modern(), open_unix(), and parse_cfile().
| enum NBDS_ERRS |
NBD server error codes.
| enum VIRT_STYLE |
| bool address_matches | ( | const char * | mask, |
| const struct sockaddr * | addr, | ||
| GError ** | err | ||
| ) |
Check whether a given address matches a given netmask.
| mask | the address or netmask to check against, in ASCII representation |
| addr | the address to check |
Definition at line 29 of file nbdsrv.c.
References getmaskbyte(), NBDS_ERR, and NBDS_ERR_GAI.
Referenced by authorized_client().
| int authorized_client | ( | CLIENT * | opts | ) |
Check whether a client is allowed to connect.
Works with an authorization file which contains one line per machine or network, with CIDR-style netmasks.
| opts | The client who's trying to connect. |
Definition at line 113 of file nbdsrv.c.
References address_matches(), SERVER::authname, CLIENT::clientaddr, LINELEN, msg, and CLIENT::server.
Referenced by handle_modern_connection().
duplicate server
| s | the old server we want to duplicate |
Definition at line 157 of file nbdsrv.c.
References SERVER::authname, SERVER::cidrlen, SERVER::cowdir, SERVER::expected_size, SERVER::exportname, SERVER::flags, SERVER::listenaddr, SERVER::max_connections, SERVER::postrun, SERVER::prerun, SERVER::servename, SERVER::transactionlog, and SERVER::virtstyle.
| int exptrim | ( | struct nbd_request * | req, |
| CLIENT * | client | ||
| ) |
Punch a hole in the backend file (if supported by the current system).
| req | the request for which this is being processed |
| client | the client for which we're processing this request |
Definition at line 240 of file nbdsrv.c.
References DEBUG, delete_treefile(), CLIENT::export, CLIENT::exportname, CLIENT::exportsize, F_COPYONWRITE, F_READONLY, F_TREEFILES, FILE_INFO::fhandle, SERVER::flags, nbd_request::from, nbd_request::len, punch_hole(), CLIENT::server, FILE_INFO::startoff, and TREEPAGESIZE.
Referenced by handle_trim(), and mainloop().
| uint8_t getmaskbyte | ( | int | masklen | ) |
Gets a byte to allow for address masking.
| masklen | the length of the requested mask. |
Definition at line 101 of file nbdsrv.c.
Referenced by address_matches(), and set_peername().
| void myseek | ( | int | handle, |
| off_t | a | ||
| ) |
seek to a position in a file, with error handling.
| handle | a filedescriptor |
| a | position to seek to |
Definition at line 292 of file nbdsrv.c.
References err().
Referenced by expread(), expwrite(), and open_treefile().
| uint64_t size_autodetect | ( | int | fhandle | ) |
Detect the size of a file.
| fhandle | An open filedescriptor |
Definition at line 199 of file nbdsrv.c.
References __attribute__, and DEBUG.
Referenced by setupexport().
1.7.3