46 #define NI_NAMESPACE_SZ 32
48 static void usage(
void)
50 printf(
"usage: ni_rsrc_namespace [OPTION]\n"
51 "Provides NETINT QUADRA NVMe block device namespace IO operations.\n"
53 " -d the nvme block namespace. Only PF with nsid 1 allowed\n"
54 " -D the nvme block namespace for target over provision setting\n"
55 " -n the nvme block namespace count.\n"
57 " -p overprovision percent. Use exclusive of -n and -s and -q\n"
58 " -q namespace QoS setting. Use exclusive of -n and -s and -p\n"
59 " Default: 0 disabled.\n"
61 " 2 enable qos with overprovision\n"
62 " -s index of virtual PCIe functions in SR-IOV tied to the \n"
63 " physical PCIe function. '0' to select physical PCIe \n"
65 " Eg. '1' to select the first virtual SR-IOV device tied \n"
66 " to the physical block device defined by '-d' option.\n"
75 if (handle == NI_INVALID_DEVICE_HANDLE)
77 fprintf(stderr,
"ERROR: open %s failure for %s\n", dev,
82 printf(
"Succeed to open block namespace %s\n", dev);
88 fprintf(stderr,
"ERROR: Config setting failure for %s\n",
99 if (handle == NI_INVALID_DEVICE_HANDLE)
101 fprintf(stderr,
"ERROR: open %s failure for %s\n", dev,
106 printf(
"Succeed to open block namespace %s\n", dev);
112 fprintf(stderr,
"ERROR: Config setting failure for %s\n",
123 if (handle == NI_INVALID_DEVICE_HANDLE)
125 fprintf(stderr,
"ERROR: open %s failure for %s\n", dev,
130 printf(
"Succeed to open block namespace %s\n", dev);
133 if (handle_t == NI_INVALID_DEVICE_HANDLE)
135 fprintf(stderr,
"ERROR: open %s failure for %s\n", devt,
141 printf(
"Succeed to open block namespace %s\n", dev);
147 fprintf(stderr,
"ERROR: Config setting failure for %s\n",
155 int main(
int argc,
char *argv[])
161 int namespace_num = 1;
162 float over_provision_percent = -1;
163 int i32_over_provision_percent = 0;
170 while ((opt =
getopt(argc, argv,
"d:D:n:p:q:s:hv")) != EOF)
178 printf(
"Release ver: %s\n"
186 strcpy(device_namespace,
optarg);
188 if (lstat(device_namespace, &sb) != 0 ||
189 (sb.st_mode & S_IFMT) != S_IFBLK)
191 fprintf(stderr,
"ERROR: Only block device is supported! "
192 "%s is not block device!\n", device_namespace);
198 strcpy(device_namespace_OP,
optarg);
205 fprintf(stderr,
"ERROR: The number of namespace cannot "
213 if (over_provision_percent > 100 || over_provision_percent < 0)
215 fprintf(stderr,
"ERROR: Overprovision percent cannot "
216 "exceed 100%% or become negative\n");
227 "ERROR: QoS mode %d not supported\n",
236 fprintf(stderr,
"ERROR: Invalid SR-IOV device index: %d\n",
242 fprintf(stderr,
"ERROR: Invalid option: %c\n", opt);
247 if (device_namespace[0] ==
'\0')
249 fprintf(stderr,
"ERROR: missing argument for -d\n");
252 if (strlen(device_namespace) < 3 ||
253 strcmp(device_namespace + strlen(device_namespace) - 2,
"n1") != 0)
255 fprintf(stderr,
"ERROR: Invalid device name %s, need n1, no vf\n", device_namespace);
261 if (namespace_num != 1 || sriov_index || over_provision_percent != -1)
264 "ERROR: QoS mode -q mutually exclusive of namespace and "
271 printf(
"QoS mode setting succeed with number of %d\n", qos_mode);
276 if (over_provision_percent != -1)
278 if (device_namespace_OP[0] ==
'\0')
280 fprintf(stderr,
"ERROR: missing argument for -D\n");
283 if (namespace_num != 1 || sriov_index || qos_mode != -1)
286 "ERROR: Overprovision percent -p mutually exclusive of "
287 "namespace and SR-IOV and QOS mode\n");
290 memcpy(&i32_over_provision_percent, &over_provision_percent,
sizeof(int32_t));
292 i32_over_provision_percent);
295 printf(
"Overprovision percent setting succeed with number of %f\n",
296 over_provision_percent);
304 printf(
"Namespace setting succeed with number of %d and SR-IOV "
306 namespace_num, sriov_index);