Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ OTHER DEALINGS IN THE SOFTWARE.
#include <sys/types.h>

#include "buffer.h"
#include <stdlib.h>


struct buffer
{
Expand Down
2 changes: 1 addition & 1 deletion buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
#ifndef __TLSPROXY_BUFFERS_H
#define __TLSPROXY_BUFFERS_H

#include <stdlib.h>
//#include <stdlib.h>
#include <sys/types.h>

typedef struct buffer buffer_t;
Expand Down
1 change: 1 addition & 0 deletions cliserv.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <config.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <syslog.h>
Expand Down
4 changes: 2 additions & 2 deletions cliserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
Send 128 bytes of zeros (reserved for future use)
*/

#include <errno.h>
// #include <errno.h>
#include <string.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <stdlib.h>

#include "nbd.h"
//#include "nbd.h"

#ifndef HAVE_FDATASYNC
#define fdatasync(arg) fsync(arg)
Expand Down
11 changes: 6 additions & 5 deletions nbd-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
*/

#include "config.h"
#include "lfs.h"
// #include "lfs.h"
#include "nbd.h"

#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/types.h>
#include <unistd.h>
#include <netinet/tcp.h>
// #include <netinet/tcp.h>
#include <netinet/in.h>
#include <netdb.h>
#include "netdb-compat.h"
// #include "netdb-compat.h"
#include <inttypes.h>
#include <stdio.h>
#include <fcntl.h>
Expand All @@ -39,12 +40,12 @@
#include <sys/mman.h>
#include <signal.h>
#include <errno.h>
#include <getopt.h>
// #include <getopt.h>
#include <stdarg.h>
#include <stdbool.h>
#include <time.h>

#include <linux/ioctl.h>
// #include <linux/ioctl.h>

#if HAVE_NETLINK
#include "nbd-netlink.h"
Expand Down
2 changes: 1 addition & 1 deletion nbd-debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifdef DODBG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#define DEBUG(...) do{}while(0)
#endif
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION ""
Expand Down
97 changes: 44 additions & 53 deletions nbd-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
#include <sys/param.h>
// #include <sys/param.h>
#include <signal.h>
#include <errno.h>
#include <libgen.h>
#include <netinet/tcp.h>
// #include <netinet/tcp.h>
#include <netinet/in.h>
#include <netdb.h>
#include <syslog.h>
Expand All @@ -98,8 +98,8 @@
#if HAVE_BLKDISCARD
#include <linux/fs.h>
#endif
#include <arpa/inet.h>
#include <strings.h>
// #include <arpa/inet.h>
// #include <strings.h>
#include <dirent.h>
#ifdef HAVE_SYS_DIR_H
#include <sys/dir.h>
Expand All @@ -111,7 +111,7 @@
#include <pwd.h>
#include <grp.h>
#include <dirent.h>
#include <ctype.h>
// #include <ctype.h>
#include <inttypes.h>

#include <glib.h>
Expand All @@ -120,7 +120,7 @@
#define MY_NAME "nbd_server"
#include "cliserv.h"
#include "nbd-debug.h"
#include "netdb-compat.h"
// #include "netdb-compat.h"
#include "backend.h"
#include "treefiles.h"
#include "nbd-helper.h"
Expand Down Expand Up @@ -226,30 +226,25 @@ struct work_package {
void* data; /**< for write requests */
};

static volatile sig_atomic_t is_sigchld_caught; /**< Flag set by
SIGCHLD handler
to mark a child
exit */

static volatile sig_atomic_t is_sigterm_caught; /**< Flag set by
SIGTERM handler
to mark a exit
request */

static volatile sig_atomic_t is_sighup_caught; /**< Flag set by SIGHUP
handler to mark a
reconfiguration
request */

GArray* modernsocks; /**< Sockets for the modern handler. Not used
if a client was only specified on the
command line; only port used if
oldstyle is set to false (and then the
command-line client isn't used, gna gna).
This may be more than one socket on
systems that don't support serving IPv4
and IPv6 from the same socket (like,
e.g., FreeBSD) */
/// Flag set by SIGCHLD handler to mark a child exit
static volatile sig_atomic_t is_sigchld_caught;

/// Flag set by SIGTERM handler to mark an exit request
static volatile sig_atomic_t is_sigterm_caught;

/// Flag set by SIGHUP handler to mark a reconfiguration request
static volatile sig_atomic_t is_sighup_caught;

/**
* Sockets for the modern handler.
* Not used if a client was only specified on the command line;
* only port used if oldstyle is set to false (and then the command-line
* client isn't used, gna gna).
* This may be more than one socket on systems that don't support serving
* IPv4 and IPv6 from the same socket (like, e.g., FreeBSD)
*/
GArray* modernsocks;

GArray* childsocks; /**< parent-side sockets for communication with children */
int commsocket; /**< child-side socket for communication with parent */
static sem_t file_wait_sem;
Expand All @@ -262,42 +257,39 @@ bool logged_oversized=false; /**< whether we logged oversized requests already
typedef enum {
PARAM_INT, /**< This parameter is an integer */
PARAM_INT64, /**< This parameter is an integer */
PARAM_STRING, /**< This parameter is a string */
PARAM_STRING, /**< This parameter is a string */
PARAM_BOOL, /**< This parameter is a boolean */
} PARAM_TYPE;

/**
* Configuration file values
**/
typedef struct {
gchar *paramname; /**< Name of the parameter, as it appears in
the config file */
gboolean required; /**< Whether this is a required (as opposed to
optional) parameter */
gchar *paramname; /**< Name of the parameter, as it appears in the config file */
gboolean required; /**< Whether this is a required (as opposed to optional) parameter */
PARAM_TYPE ptype; /**< Type of the parameter. */
gpointer target; /**< Pointer to where the data of this
parameter should be written. If ptype is
PARAM_BOOL, the data is or'ed rather than
overwritten. */
gint flagval; /**< Flag mask for this parameter in case ptype
is PARAM_BOOL. */
gint flagval; /**< Flag mask for this parameter in case ptype is PARAM_BOOL. */
} PARAM;

/**
* Configuration file values of the "generic" section
**/
struct generic_conf {
gchar *user; /**< user we run the server as */
gchar *group; /**< group we run running as */
gchar *modernaddr; /**< address of the modern socket */
gchar *modernport; /**< port of the modern socket */
gchar *unixsock; /**< file name of the unix domain socket */
gchar *certfile; /**< certificate file */
gchar *keyfile; /**< key file */
gchar *cacertfile; /**< CA certificate file */
gchar *tlsprio; /**< TLS priority string */
gint flags; /**< global flags */
gint threads; /**< maximum number of parallel threads we want to run */
gchar *user; /**< user we run the server as */
gchar *group; /**< group we run running as */
gchar *modernaddr; /**< address of the modern socket */
gchar *modernport; /**< port of the modern socket */
gchar *unixsock; /**< file name of the unix domain socket */
gchar *certfile; /**< certificate file */
gchar *keyfile; /**< key file */
gchar *cacertfile; /**< CA certificate file */
gchar *tlsprio; /**< TLS priority string */
gint flags; /**< global flags */
gint threads; /**< maximum number of parallel threads we want to run */
};

#if HAVE_GNUTLS
Expand Down Expand Up @@ -379,9 +371,8 @@ static void socket_read(CLIENT* client, void *buf, size_t len) {
* @param bufsiz the size of the buffer
**/
static inline void consume(CLIENT* c, size_t len, void * buf, size_t bufsiz) {
size_t curlen;
while (len>0) {
curlen = (len>bufsiz)?bufsiz:len;
const size_t curlen = (len>bufsiz)?bufsiz:len;
socket_read(c, buf, curlen);
len -= curlen;
}
Expand Down Expand Up @@ -555,7 +546,7 @@ SERVER* cmdline(int argc, char *argv[], struct generic_conf *genconf) {
int i=0;
int nonspecial=0;
int c;
struct option long_options[] = {
const struct option long_options[] = {
{"read-only", no_argument, NULL, 'r'},
{"multi-file", no_argument, NULL, 'm'},
{"copy-on-write", no_argument, NULL, 'c'},
Expand Down Expand Up @@ -1199,7 +1190,7 @@ int get_filepos(CLIENT *client, off_t a, int* fhandle, off_t* foffset, size_t* m
* @param fua Flag to indicate 'Force Unit Access'
* @return The number of bytes actually written, or -1 in case of an error
**/
ssize_t rawexpwrite(off_t a, char *buf, size_t len, CLIENT *client, int fua) {
ssize_t rawexpwrite(off_t a, const char *buf, size_t len, CLIENT *client, int fua) {
int fhandle;
off_t foffset;
size_t maxbytes;
Expand Down Expand Up @@ -1272,7 +1263,7 @@ ssize_t rawexpwrite(off_t a, char *buf, size_t len, CLIENT *client, int fua) {
* @param fua Flag to indicate 'Force Unit Access'
* @return 0 on success, nonzero on failure
**/
int rawexpwrite_fully(off_t a, char *buf, size_t len, CLIENT *client, int fua) {
int rawexpwrite_fully(off_t a, const char *buf, size_t len, CLIENT *client, int fua) {
ssize_t ret=0;

while(len > 0 && (ret=rawexpwrite(a, buf, len, client, fua)) > 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion nbd-trdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
// #include <sys/time.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
Expand Down
3 changes: 2 additions & 1 deletion nbd-trplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
*/

#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
// #include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion nbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef LINUX_NBD_H
#define LINUX_NBD_H

//#include <linux/types.h>
#include <stdint.h>

#define NBD_SET_SOCK _IO( 0xab, 0 )
#define NBD_SET_BLKSIZE _IO( 0xab, 1 )
Expand Down
5 changes: 4 additions & 1 deletion nbdclt.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef NBDCLT_H
#define NBDCLT_H

#include <stdint.h>
#include <stdbool.h>

typedef struct {
char *name;
char *dev;
Expand All @@ -23,7 +26,7 @@ typedef struct {
bool preinit;
bool force_ro;
bool tls;
bool persist_mode;
bool persist_mode;
char *priority;
int dead_conn_timeout;
} CLIENT;
Expand Down
Loading