1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/* NBD client library in userspace
* Copyright Red Hat
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Handle --can and --cannot flags (and synonyms). */
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <libnbd.h>
#include "nbdinfo.h"
int can_exit_code;
void
do_can (void)
{
int feature;
assert (can);
if (strcasecmp (can, "connect") == 0 ||
strcasecmp (can, "read") == 0)
feature = 1;
else if (strcasecmp (can, "tls") == 0)
feature = nbd_get_tls_negotiated (nbd);
else if (strcasecmp (can, "sr") == 0 ||
strcasecmp (can, "structured") == 0 ||
strcasecmp (can, "structured reply") == 0 ||
strcasecmp (can, "structured-reply") == 0 ||
strcasecmp (can, "structured_reply") == 0 ||
strcasecmp (can, "structured replies") == 0 ||
strcasecmp (can, "structured-replies") == 0 ||
strcasecmp (can, "structured_replies") == 0)
feature = nbd_get_structured_replies_negotiated (nbd);
else if (strcasecmp (can, "eh") == 0 ||
strcasecmp (can, "extended header") == 0 ||
strcasecmp (can, "extended-header") == 0 ||
strcasecmp (can, "extended_header") == 0 ||
strcasecmp (can, "extended headers") == 0 ||
strcasecmp (can, "extended-headers") == 0 ||
strcasecmp (can, "extended_headers") == 0)
feature = nbd_get_extended_headers_negotiated (nbd);
else if (strcasecmp (can, "readonly") == 0 ||
strcasecmp (can, "read-only") == 0 ||
strcasecmp (can, "read_only") == 0)
feature = nbd_is_read_only (nbd);
else if (strcasecmp (can, "write") == 0) {
feature = nbd_is_read_only (nbd);
if (feature >= 0) feature = !feature;
}
else if (strcasecmp (can, "rotational") == 0)
feature = nbd_is_rotational (nbd);
else if (strcasecmp (can, "block status payload") == 0 ||
strcasecmp (can, "block-status-payload") == 0 ||
strcasecmp (can, "block_status_payload") == 0)
feature = nbd_can_block_status_payload (nbd);
else if (strcasecmp (can, "cache") == 0)
feature = nbd_can_cache (nbd);
else if (strcasecmp (can, "df") == 0)
feature = nbd_can_df (nbd);
else if (strcasecmp (can, "fastzero") == 0 ||
strcasecmp (can, "fast-zero") == 0 ||
strcasecmp (can, "fast_zero") == 0)
feature = nbd_can_fast_zero (nbd);
else if (strcasecmp (can, "flush") == 0)
feature = nbd_can_flush (nbd);
else if (strcasecmp (can, "fua") == 0)
feature = nbd_can_fua (nbd);
else if (strcasecmp (can, "multiconn") == 0 ||
strcasecmp (can, "multi-conn") == 0 ||
strcasecmp (can, "multi_conn") == 0)
feature = nbd_can_multi_conn (nbd);
else if (strcasecmp (can, "trim") == 0)
feature = nbd_can_trim (nbd);
else if (strcasecmp (can, "zero") == 0)
feature = nbd_can_zero (nbd);
else {
const char *what =
!cannot ? "--can/--is/--has" : "--cannot/--isnt/--hasnt";
fprintf (stderr, "%s: unknown %s option: %s\n", progname, what, can);
exit (EXIT_FAILURE);
}
if (feature == -1) {
fprintf (stderr, "%s: %s\n", progname, nbd_get_error ());
exit (EXIT_FAILURE);
}
/* If cannot, negate the result. */
if (cannot)
feature = !feature;
/* Translate the feature bool into an exit code. This is used in main(). */
can_exit_code = feature ? EXIT_SUCCESS : 2;
}
|