gchar* postrun; /**< command that will be ran after the client
disconnects */
gchar* servename; /**< name of the export as selected by nbd-client */
gchar* postrun; /**< command that will be ran after the client
disconnects */
gchar* servename; /**< name of the export as selected by nbd-client */
"\t-r|--read-only\t\tread only\n"
"\t-m|--multi-file\t\tmultiple file\n"
"\t-c|--copy-on-write\tcopy on write\n"
"\t-C|--config-file\tspecify an alternate configuration file\n"
"\t-l|--authorize-file\tfile with list of hosts that are allowed to\n\t\t\t\tconnect.\n"
"\t-p|--pid-file\t\tspecify a filename to write our PID to\n"
"\t-r|--read-only\t\tread only\n"
"\t-m|--multi-file\t\tmultiple file\n"
"\t-c|--copy-on-write\tcopy on write\n"
"\t-C|--config-file\tspecify an alternate configuration file\n"
"\t-l|--authorize-file\tfile with list of hosts that are allowed to\n\t\t\t\tconnect.\n"
"\t-p|--pid-file\t\tspecify a filename to write our PID to\n"
- "\t-o|--output-config\toutput a config file section for what you\n\t\t\t\tspecified on the command line, with the\n\t\t\t\tspecified section name\n\n"
+ "\t-o|--output-config\toutput a config file section for what you\n\t\t\t\tspecified on the command line, with the\n\t\t\t\tspecified section name\n"
+ "\t-M|--max-connections\tspecify the maximum number of opened connections\n\n"
"\tif port is set to 0, stdin is used (for running from inetd)\n"
"\tif file_to_export contains '%%s', it is substituted with the IP\n"
"\t\taddress of the machine trying to connect\n"
"\tif port is set to 0, stdin is used (for running from inetd)\n"
"\tif file_to_export contains '%%s', it is substituted with the IP\n"
"\t\taddress of the machine trying to connect\n"
{"config-file", required_argument, NULL, 'C'},
{"pid-file", required_argument, NULL, 'p'},
{"output-config", required_argument, NULL, 'o'},
{"config-file", required_argument, NULL, 'C'},
{"pid-file", required_argument, NULL, 'p'},
{"output-config", required_argument, NULL, 'o'},
- while((c=getopt_long(argc, argv, "-C:cl:mo:rp:", long_options, &i))>=0) {
+ while((c=getopt_long(argc, argv, "-C:cl:mo:rp:M:", long_options, &i))>=0) {
{ "sdp", FALSE, PARAM_BOOL, NULL, F_SDP },
{ "sync", FALSE, PARAM_BOOL, NULL, F_SYNC },
{ "listenaddr", FALSE, PARAM_STRING, NULL, 0 },
{ "sdp", FALSE, PARAM_BOOL, NULL, F_SDP },
{ "sync", FALSE, PARAM_BOOL, NULL, F_SYNC },
{ "listenaddr", FALSE, PARAM_STRING, NULL, 0 },
PARAM gp[] = {
{ "user", FALSE, PARAM_STRING, &runuser, 0 },
{ "group", FALSE, PARAM_STRING, &rungroup, 0 },
PARAM gp[] = {
{ "user", FALSE, PARAM_STRING, &runuser, 0 },
{ "group", FALSE, PARAM_STRING, &rungroup, 0 },
lp[10].target=lp[11].target=
lp[12].target=&(s.flags);
lp[13].target=&(s.listenaddr);
lp[10].target=lp[11].target=
lp[12].target=&(s.flags);
lp[13].target=&(s.listenaddr);
memset(zeros, '\0', sizeof(zeros));
if(!client || !client->modern) {
memset(zeros, '\0', sizeof(zeros));
if(!client || !client->modern) {
if (write(net, INIT_PASSWD, 8) < 0) {
err_nonfatal("Negotiation failed: %m");
if(client)
exit(EXIT_FAILURE);
}
if (write(net, INIT_PASSWD, 8) < 0) {
err_nonfatal("Negotiation failed: %m");
if(client)
exit(EXIT_FAILURE);
}
if (write(net, &magic, sizeof(magic)) < 0) {
err_nonfatal("Negotiation failed: %m");
if(client)
if (write(net, &magic, sizeof(magic)) < 0) {
err_nonfatal("Negotiation failed: %m");
if(client)
- write(net, &smallflags, sizeof(uint16_t));
- read(net, &reserved, sizeof(reserved));
- read(net, &magic, sizeof(magic));
+ if (write(net, &smallflags, sizeof(uint16_t)) < 0)
+ err("Negotiation failed: %m");
+ if (read(net, &reserved, sizeof(reserved)) < 0)
+ err("Negotiation failed: %m");
+ if (read(net, &magic, sizeof(magic)) < 0)
+ err("Negotiation failed: %m");
- read(net, &opt, sizeof(opt));
+ if (read(net, &opt, sizeof(opt)) < 0)
+ err("Negotiation failed: %m");
- read(net, &namelen, sizeof(namelen));
- namelen = ntohll(namelen);
+ if (read(net, &namelen, sizeof(namelen)) < 0)
+ err("Negotiation failed: %m");
+ namelen = ntohl(namelen);
- name[namelen+1]=0;
- read(net, &name, namelen);
+ name[namelen]=0;
+ if (read(net, name, namelen) < 0)
+ err("Negotiation failed: %m");
for(i=0; i<servers->len; i++) {
SERVER* serve = &(g_array_index(servers, SERVER, i));
if(!strcmp(serve->servename, name)) {
for(i=0; i<servers->len; i++) {
SERVER* serve = &(g_array_index(servers, SERVER, i));
if(!strcmp(serve->servename, name)) {
size_host = htonll((u64)(client->exportsize));
if (write(net, &size_host, 8) < 0)
err("Negotiation failed: %m");
if (client->server->flags & F_READONLY)
flags |= NBD_FLAG_READ_ONLY;
size_host = htonll((u64)(client->exportsize));
if (write(net, &size_host, 8) < 0)
err("Negotiation failed: %m");
if (client->server->flags & F_READONLY)
flags |= NBD_FLAG_READ_ONLY;
- flags = htonl(flags);
- if (write(client->net, &flags, 4) < 0)
- err("Negotiation failed: %m");
+ if (!client->modern) {
+ /* oldstyle */
+ flags = htonl(flags);
+ if (write(client->net, &flags, 4) < 0)
+ err("Negotiation failed: %m");
+ } else {
+ /* modern */
+ smallflags = (uint16_t)(flags & ~((uint16_t)0));
+ smallflags = htons(smallflags);
+ if (write(client->net, &smallflags, sizeof(smallflags)) < 0) {
+ err("Negotiation failed: %m");
+ }
+ }
+ /* common */
if (write(client->net, zeros, 124) < 0)
err("Negotiation failed: %m");
return NULL;
if (write(client->net, zeros, 124) < 0)
err("Negotiation failed: %m");
return NULL;
memset(&hints,'\0',sizeof(hints));
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_NUMERICSERV;
hints.ai_socktype = SOCK_STREAM;
memset(&hints,'\0',sizeof(hints));
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_NUMERICSERV;
hints.ai_socktype = SOCK_STREAM;
- g_warning("Could not parse config file: %s",
- err ? err->message : "Unknown error");
+ if(err && !(err->domain == g_quark_from_string("parse_cfile")
+ && err->code == CFILE_NOTFOUND)) {
+ g_warning("Could not parse config file: %s",
+ err ? err->message : "Unknown error");
+ }