38 #if defined(__linux__) || defined(__APPLE__)
40 #include <sys/types.h>
50 #define DEV_NAME_PREFIX "\\\\.\\Scsi"
51 #elif defined(__linux__)
52 #define DEV_NAME_PREFIX "/dev/nvme"
53 #define NVME_PCI_PREFIX "nvme/nvme"
54 #define NVME_SUBSYS_PREFIX "nvme-subsystem/nvme-subsys"
55 #elif defined(__APPLE__)
56 #define DEV_NAME_PREFIX "/dev/disk"
68 static int get_device_name(
const char *p_in_buf,
char *p_out_buf,
int out_buf_len)
71 char cmd[128] = {
'\0'};
72 char cmd_ret[128] = {
'\0'};
76 if (!p_in_buf || !p_out_buf)
85 snprintf(p_out_buf, out_buf_len,
"%s", p_in_buf);
87 #elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
88 ni_log(
NI_LOG_TRACE,
"The block path is same as device path in Linux virtual machine with VirtIO driver.\n");
89 snprintf(p_out_buf, out_buf_len,
"%s", p_in_buf);
91 #elif defined(__APPLE__)
92 snprintf(p_out_buf, out_buf_len,
"%s", p_in_buf);
96 ni_log(
NI_LOG_TRACE,
"For Android, assume index block namespace is same as device index\n");
97 p_src = strstr(p_in_buf,
"/nvme");
100 int len = strlen(
"/nvme");
101 strcpy(p_out_buf, p_in_buf);
104 while (isdigit(*p_src))
113 snprintf(cmd,
sizeof(cmd) - 1,
"udevadm info -q path -n %s", p_in_buf);
116 if (access(p_in_buf, F_OK) == -1)
122 cmd_fp = popen(cmd,
"r");
128 if (fgets(cmd_ret,
sizeof(cmd_ret)/
sizeof(cmd_ret[0]), cmd_fp) != NULL)
130 p_src = strstr(cmd_ret, NVME_PCI_PREFIX);
133 p_src += strlen(NVME_PCI_PREFIX);
137 p_src = strstr(cmd_ret, NVME_SUBSYS_PREFIX);
140 p_src += strlen(NVME_SUBSYS_PREFIX);
150 strcpy(p_out_buf, DEV_NAME_PREFIX);
151 p_dst += strlen(DEV_NAME_PREFIX);
152 while (isdigit(*p_src))
170 static void display_help(
void)
172 printf(
"-------- ni_rsrc_update_logan v%s --------\n"
173 "Update NetInt Logan transcoder resource (encoders and decoders) status.\n"
174 "-a <nvme_device> Create a resource entry for a newly active transcoder. (eg. /dev/nvme0) \n"
175 "-d <nvme_device> Delete the resource entry for a removed transcoder card. (eg. /dev/nvme0)\n"
176 "-r Init transcoder card resource regardless firmware release version to \n"
177 " libxcoder_logan version compatibility. Must be used with -a option.\n"
178 " Default: only init cards with compatible firmware version.\n"
179 "-c Only init if all cards are fully compatible. Must be used with -a option.\n"
180 " Default: init as many fully and partially cards as possible.\n"
181 "-l Set loglevel of libxcoder_logan API.\n"
182 " [none, fatal, error, info, debug, trace]\n"
184 "-v Show libxcoder_logan version.\n"
195 int main(
int argc,
char *argv[])
198 char char_dev_name[64];
199 int should_match_rev = 1;
200 int init_no_compat_check = 0;
201 int init_only_if_full_compat = 0;
211 while ((opt =
getopt(argc, argv,
"hvrca:d:l:")) != -1) {
215 rc = get_device_name(
optarg, char_dev_name,
sizeof(char_dev_name));
221 rc = get_device_name(
optarg, char_dev_name,
sizeof(char_dev_name));
226 init_no_compat_check = 1;
229 init_only_if_full_compat = 1;
232 if (!strcmp(
optarg,
"none")) {
234 }
else if (!strcmp(
optarg,
"fatal")) {
236 }
else if (!strcmp(
optarg,
"error")) {
238 }
else if (!strcmp(
optarg,
"info")) {
240 }
else if (!strcmp(
optarg,
"debug")) {
242 }
else if (!strcmp(
optarg,
"trace")) {
245 fprintf(stderr,
"unknown log level selected: %s",
optarg);
260 if (add_dev && delete_dev)
262 fprintf(stderr,
"Error: can not add and delete device at the same time\n\n");
267 if (init_no_compat_check && init_only_if_full_compat)
269 fprintf(stderr,
"Error: -r option cannot be used with -c option\n\n");
274 if ((init_no_compat_check || init_only_if_full_compat) && !add_dev)
276 fprintf(stderr,
"Error: %s option must be used with -a option\n\n",
277 init_no_compat_check ?
"-r" :
"-c");
283 if (init_no_compat_check)
285 should_match_rev = 0;
287 else if (init_only_if_full_compat)
289 should_match_rev = 2;
295 printf(
"%s not added as transcoder.\n",
optarg);
297 printf(
"Added transcoder %s successfully.\n", char_dev_name);
303 printf(
"%s not removed as transcoder.\n",
optarg);
305 printf(
"Removed transcoder %s successfully.\n", char_dev_name);
Common NETINT definitions used by all modules.
@ NI_LOGAN_RETCODE_FAILURE
#define NI_LOGAN_XCODER_REVISION
int getopt(int argc, char *argv[], const char *optstring)
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
int ni_logan_rsrc_add_device(const char *dev, int should_match_rev)
Add an NetInt h/w device into resource pool on the host.
int ni_logan_rsrc_remove_device(const char *dev)
Remove an NetInt h/w device from resource pool on the host.
Exported definitions related to resource management of NI T-408 devices.
Private definitions related to resource management of NI T-408 devices.
int main(int argc, char *argv[])
Exported utility routines definition.