@@ -164,7 +164,7 @@ static struct nl_sock *get_nbd_socket(int *driver_id) {
164
164
165
165
static void netlink_configure (int index , int * sockfds , int num_connects ,
166
166
u64 size64 , int blocksize , uint16_t flags ,
167
- int timeout ) {
167
+ int timeout , const char * identifier ) {
168
168
struct nl_sock * socket ;
169
169
struct nlattr * sock_attr ;
170
170
struct nl_msg * msg ;
@@ -186,6 +186,8 @@ static void netlink_configure(int index, int *sockfds, int num_connects,
186
186
NLA_PUT_U64 (msg , NBD_ATTR_SERVER_FLAGS , flags );
187
187
if (timeout )
188
188
NLA_PUT_U64 (msg , NBD_ATTR_TIMEOUT , timeout );
189
+ if (identifier )
190
+ NLA_PUT_STRING (msg , NBD_ATTR_BACKEND_IDENTIFIER , identifier );
189
191
190
192
sock_attr = nla_nest_start (msg , NBD_ATTR_SOCKETS );
191
193
if (!sock_attr )
@@ -246,7 +248,7 @@ static void netlink_disconnect(char *nbddev) {
246
248
#else
247
249
static void netlink_configure (int index , int * sockfds , int num_connects ,
248
250
u64 size64 , int blocksize , uint16_t flags ,
249
- int timeout )
251
+ int timeout , const char * identifier )
250
252
{
251
253
}
252
254
@@ -875,7 +877,7 @@ void usage(char* errmsg, ...) {
875
877
fprintf (stderr , "%s version %s\n" , PROG_NAME , PACKAGE_VERSION );
876
878
}
877
879
#if HAVE_NETLINK
878
- fprintf (stderr , "Usage: nbd-client -name|-N name host [port] nbd_device\n\t[-block-size|-b block size] [-timeout|-t timeout] [-swap|-s]\n\t[-persist|-p] [-nofork|-n] [-systemd-mark|-m] [-nonetlink|-L]\n\t[-readonly|-R] [-size|-B bytes] [-preinit|-P]\n" );
880
+ fprintf (stderr , "Usage: nbd-client -name|-N name host [port] nbd_device\n\t[-block-size|-b block size] [-timeout|-t timeout] [-swap|-s]\n\t[-persist|-p] [-nofork|-n] [-systemd-mark|-m] [-i ident|- nonetlink|-L]\n\t[-readonly|-R] [-size|-B bytes] [-preinit|-P]\n" );
879
881
#else
880
882
fprintf (stderr , "Usage: nbd-client -name|-N name host [port] nbd_device\n\t[-block-size|-b block size] [-timeout|-t timeout] [-swap|-s]\n\t[-persist|-p] [-nofork|-n] [-systemd-mark|-m]\n\t[-readonly|-R] [-size|-B bytes] [-preinit|-P]\n" );
881
883
#endif
@@ -914,7 +916,7 @@ void disconnect(char* device) {
914
916
915
917
static const char * short_opts = "-B:b:c:d:gH:hlnN:PpRSst:uVxy:"
916
918
#if HAVE_NETLINK
917
- "L"
919
+ "i: L"
918
920
#endif
919
921
#if HAVE_GNUTLS
920
922
"A:C:F:K:"
@@ -935,6 +937,7 @@ int main(int argc, char *argv[]) {
935
937
uint32_t opts = 0 ;
936
938
sigset_t block , old ;
937
939
struct sigaction sa ;
940
+ char * identifier = NULL ;
938
941
int netlink = HAVE_NETLINK ;
939
942
int need_disconnect = 0 ;
940
943
int * sockfds ;
@@ -949,6 +952,9 @@ int main(int argc, char *argv[]) {
949
952
{ "no-optgo" , no_argument , NULL , 'g' },
950
953
{ "help" , no_argument , NULL , 'h' },
951
954
{ "tlshostname" , required_argument , NULL , 'H' },
955
+ #if HAVE_NETLINK
956
+ { "identifier" , required_argument , NULL , 'i' },
957
+ #endif
952
958
{ "keyfile" , required_argument , NULL , 'K' },
953
959
{ "list" , no_argument , NULL , 'l' },
954
960
#if HAVE_NETLINK
@@ -1053,6 +1059,11 @@ int main(int argc, char *argv[]) {
1053
1059
case 'h' :
1054
1060
usage (NULL );
1055
1061
exit (EXIT_SUCCESS );
1062
+ #if HAVE_NETLINK
1063
+ case 'i' :
1064
+ identifier = optarg ;
1065
+ break ;
1066
+ #endif
1056
1067
case 'l' :
1057
1068
needed_flags |= NBD_FLAG_FIXED_NEWSTYLE ;
1058
1069
opts |= NBDC_DO_LIST ;
@@ -1180,6 +1191,10 @@ int main(int argc, char *argv[]) {
1180
1191
1181
1192
if (netlink )
1182
1193
nofork = 1 ;
1194
+ else if (identifier ) {
1195
+ fprintf (stderr , "E: identifier is only useful with netlink\n" );
1196
+ exit (EXIT_FAILURE );
1197
+ }
1183
1198
1184
1199
if ((cur_client -> force_size64 % cur_client -> bs ) != 0 ) {
1185
1200
fprintf (stderr , "E: size (%" PRIu64 " bytes) is not a multiple of blocksize (%d)!\n" , cur_client -> force_size64 , cur_client -> bs );
@@ -1246,7 +1261,8 @@ int main(int argc, char *argv[]) {
1246
1261
err ("Invalid nbd device target\n" );
1247
1262
}
1248
1263
netlink_configure (index , sockfds , cur_client -> nconn ,
1249
- cur_client -> size64 , cur_client -> bs , flags , cur_client -> timeout );
1264
+ cur_client -> size64 , cur_client -> bs , flags , cur_client -> timeout ,
1265
+ identifier );
1250
1266
return 0 ;
1251
1267
}
1252
1268
/* Go daemon */
0 commit comments