47 #define NI_NAMESPACE_SZ 32
49 static void usage(
void)
51 printf(
"usage: ni_rsrc_namespace [OPTION]\n"
52 "Provides NETINT QUADRA NVMe block device namespace IO operations.\n"
54 " -d the nvme block namespace. Only PF with nsid 1 allowed\n"
55 " -D the nvme block namespace for target over provision setting\n"
56 " -n the nvme block namespace count.\n"
58 " -p overprovision percent. Use exclusive of -n and -s and -q\n"
59 " -q namespace QoS setting. Use exclusive of -n and -s and -p\n"
60 " Default: 0 disabled.\n"
62 " 2 enable qos with overprovision\n"
63 " -s index of virtual PCIe functions in SR-IOV tied to the \n"
64 " physical PCIe function. '0' to select physical PCIe \n"
66 " Eg. '1' to select the first virtual SR-IOV device tied \n"
67 " to the physical block device defined by '-d' option.\n"
69 " -c Persist the configuration of the namespace\n"
78 if (handle == NI_INVALID_DEVICE_HANDLE)
81 fprintf(stderr,
"ERROR: open %s failure for %s\n", dev,
86 printf(
"Succeed to open block namespace %s\n", dev);
93 fprintf(stderr,
"ERROR: Config setting failure for %s\n",
105 if (handle == NI_INVALID_DEVICE_HANDLE)
108 fprintf(stderr,
"ERROR: open %s failure for %s\n", dev,
113 printf(
"Succeed to open block namespace %s\n", dev);
120 fprintf(stderr,
"ERROR: Config setting failure for %s\n",
132 if (handle == NI_INVALID_DEVICE_HANDLE)
135 fprintf(stderr,
"ERROR: open %s failure for %s\n", dev,
140 printf(
"Succeed to open block namespace %s\n", dev);
143 if (handle_t == NI_INVALID_DEVICE_HANDLE)
146 fprintf(stderr,
"ERROR: open %s failure for %s\n", devt,
152 printf(
"Succeed to open block namespace %s\n", dev);
159 fprintf(stderr,
"ERROR: Config setting failure for %s\n",
167 int main(
int argc,
char *argv[])
173 int namespace_num = 1;
174 float over_provision_percent = -1;
175 int i32_over_provision_percent = 0;
183 while ((opt =
getopt(argc, argv,
"d:D:n:p:q:s:chv")) != EOF)
191 printf(
"Release ver: %s\n"
201 if (lstat(device_namespace, &sb) != 0 ||
202 (sb.st_mode & S_IFMT) != S_IFBLK)
204 fprintf(stderr,
"ERROR: Only block device is supported! "
205 "%s is not block device!\n", device_namespace);
218 fprintf(stderr,
"ERROR: The number of namespace cannot "
226 if (over_provision_percent > 100 || over_provision_percent < 0)
228 fprintf(stderr,
"ERROR: Overprovision percent cannot "
229 "exceed 100%% or become negative\n");
240 "ERROR: QoS mode %d not supported\n",
249 fprintf(stderr,
"ERROR: Invalid SR-IOV device index: %d\n",
258 fprintf(stderr,
"ERROR: Invalid option: %c\n", opt);
263 if (device_namespace[0] ==
'\0')
265 fprintf(stderr,
"ERROR: missing argument for -d\n");
268 if (strlen(device_namespace) < 3 ||
269 strcmp(device_namespace + strlen(device_namespace) - 2,
"n1") != 0)
271 fprintf(stderr,
"ERROR: Invalid device name %s, need n1, no vf\n", device_namespace);
277 if (namespace_num != 1 || sriov_index || over_provision_percent != -1)
280 "ERROR: QoS mode -q mutually exclusive of namespace and "
287 printf(
"QoS mode setting succeed with number of %d\n", qos_mode);
292 if (over_provision_percent != -1)
294 if (device_namespace_OP[0] ==
'\0')
296 fprintf(stderr,
"ERROR: missing argument for -D\n");
299 if (namespace_num != 1 || sriov_index || qos_mode != -1)
302 "ERROR: Overprovision percent -p mutually exclusive of "
303 "namespace and SR-IOV and QOS mode\n");
306 memcpy(&i32_over_provision_percent, &over_provision_percent,
sizeof(int32_t));
308 i32_over_provision_percent);
311 printf(
"Overprovision percent setting succeed with number of %f\n",
312 over_provision_percent);
317 if (persistence) namespace_num += 256;
321 printf(
"Namespace setting succeed with number of %d and SR-IOV "
323 namespace_num, sriov_index);