Added control socket, doesn't do anything yet.
This commit is contained in:
16
flexnbd.c
16
flexnbd.c
@@ -14,10 +14,14 @@
|
||||
void syntax()
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Syntax: flexnbd serve <IP address> <port> <file> [ip addresses ...]\n"
|
||||
"Syntax: flexnbd serve <listen IP address> <port> <file> \\\n"
|
||||
" [full path to control socket] \\\n"
|
||||
" [allowed connection addresses ...]\n"
|
||||
" flexnbd mirror <control socket> <dst IP address> <dst port>\n"
|
||||
" flexnbd status <control socket>\n"
|
||||
" flexnbd read <IP address> <port> <offset> <length> > data\n"
|
||||
" flexnbd write <IP address> <port> <offset> <length> < data\n"
|
||||
" flexnbd write <IP address> <port> <offset> <data file>\n"
|
||||
" flexnbd write <IP address> <port> <offset> <file to write>\n"
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
@@ -102,7 +106,7 @@ void params_serve(
|
||||
char* s_port,
|
||||
char* s_file,
|
||||
int acl_entries,
|
||||
char** s_acl_entries
|
||||
char** s_acl_entries /* first may actually be path to control socket */
|
||||
)
|
||||
{
|
||||
int parsed;
|
||||
@@ -120,6 +124,12 @@ void params_serve(
|
||||
SERVER_ERROR("Couldn't parse server address '%s' (use 0 if "
|
||||
"you want to bind to all IPs)", s_ip_address);
|
||||
|
||||
if (acl_entries > 0 && s_acl_entries[0][0] == '/') {
|
||||
out->control_socket_name = s_acl_entries[0];
|
||||
s_acl_entries++;
|
||||
acl_entries--;
|
||||
}
|
||||
|
||||
out->acl_entries = acl_entries;
|
||||
parsed = parse_acl(&out->acl, acl_entries, s_acl_entries);
|
||||
if (parsed != acl_entries)
|
||||
|
2
ioutil.c
2
ioutil.c
@@ -44,7 +44,7 @@ char* build_allocation_map(int fd, off64_t size, int resolution)
|
||||
fiemap->fm_extent_count = fiemap->fm_mapped_extents;
|
||||
fiemap->fm_mapped_extents = 0;
|
||||
|
||||
if (ioctl(fd, FS_IOC_FIEMAP, fiemap) < -1)
|
||||
if (ioctl(fd, FS_IOC_FIEMAP, fiemap) < 0)
|
||||
return NULL;
|
||||
|
||||
for (i=0;i<fiemap->fm_mapped_extents;i++) {
|
||||
|
3
params.h
3
params.h
@@ -27,9 +27,10 @@ struct mode_serve_params {
|
||||
struct ip_and_mask** acl;
|
||||
char* filename;
|
||||
int tcp_backlog;
|
||||
char* control_socket_name;
|
||||
|
||||
int server;
|
||||
int threads;
|
||||
int control;
|
||||
|
||||
char* block_allocation_map;
|
||||
};
|
||||
|
28
serve.c
28
serve.c
@@ -7,6 +7,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/un.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <string.h>
|
||||
@@ -315,7 +316,7 @@ int is_included_in_acl(int list_length, struct ip_and_mask** list, struct sockad
|
||||
return 0;
|
||||
}
|
||||
|
||||
void serve_open_socket(struct mode_serve_params* params)
|
||||
void serve_open_server_socket(struct mode_serve_params* params)
|
||||
{
|
||||
params->server = socket(PF_INET, SOCK_STREAM, 0);
|
||||
|
||||
@@ -334,6 +335,28 @@ void serve_open_socket(struct mode_serve_params* params)
|
||||
);
|
||||
}
|
||||
|
||||
void serve_open_control_socket(struct mode_serve_params* params)
|
||||
{
|
||||
struct sockaddr_un bind_address;
|
||||
|
||||
if (!params->control_socket_name)
|
||||
return;
|
||||
|
||||
params->control = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
SERVER_ERROR_ON_FAILURE(params->control,
|
||||
"Couldn't create control socket");
|
||||
|
||||
memset(&bind_address, 0, sizeof(bind_address));
|
||||
bind_address.sun_family = AF_UNIX;
|
||||
strcpy(bind_address.sun_path, params->control_socket_name);
|
||||
|
||||
SERVER_ERROR_ON_FAILURE(
|
||||
bind(params->control, &bind_address, sizeof(bind_address)),
|
||||
"Couldn't bind control socket to %s",
|
||||
params->control_socket_name
|
||||
);
|
||||
}
|
||||
|
||||
void serve_accept_loop(struct mode_serve_params* params)
|
||||
{
|
||||
while (1) {
|
||||
@@ -384,7 +407,8 @@ void serve_init_allocation_map(struct mode_serve_params* params)
|
||||
|
||||
void do_serve(struct mode_serve_params* params)
|
||||
{
|
||||
serve_open_socket(params);
|
||||
serve_open_server_socket(params);
|
||||
serve_open_control_socket(params);
|
||||
serve_init_allocation_map(params);
|
||||
serve_accept_loop(params);
|
||||
}
|
||||
|
Reference in New Issue
Block a user