Skip to content

Commit

Permalink
Added more detailed error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoutoupis committed Dec 21, 2021
1 parent c781fc2 commit b3f0683
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
3 changes: 0 additions & 3 deletions doc/rapiddisk.1
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ Define the NVMe Target port's transfer protocol (i.e. tcp or rdma).
-u
Unmap a RapidDisk device from another block device.
.TP
-v
Display the utility version string.
.TP
-X
Remove the NVMe Target port (must be unused).
.TP
Expand Down
52 changes: 26 additions & 26 deletions src/nvmet.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ int nvmet_export_volume(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigne
sprintf(path, "%s/%s%s-%s", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if (access(path, F_OK) != SUCCESS) {
if ((rc = mkdir(path, mode)) != SUCCESS) {
printf("%s: mkdir: %s\n", __func__, strerror(errno));
printf("Error. Unable to create target directory %s.\n%s: mkdir: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
}
Expand All @@ -306,7 +306,7 @@ int nvmet_export_volume(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigne
if (strlen(host) == 0) {
sprintf(path, "%s/%s%s-%s/allowed_hosts", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if ((err = scandir(path, &list, NULL, NULL)) < 0) {
printf("%s: scandir: %s\n", __func__, strerror(errno));
printf("Error. Unable to access %s.\n%s: scandir: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
for (n = 0; n < err; n++) if (list[n] != NULL) free(list[n]); /* clear list */
Expand All @@ -317,7 +317,7 @@ int nvmet_export_volume(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigne

sprintf(path, "%s/%s%s-%s/attr_allow_any_host", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if((fp = fopen(path, "w")) == NULL){
printf("%s: fopen: %s\n", __func__, strerror(errno));
printf("Error. Unable to open %s.\n%s: fopen: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
fprintf(fp, "1");
Expand All @@ -328,7 +328,7 @@ int nvmet_export_volume(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigne
sprintf(path, "%s/%s", SYS_NVMET_HOSTS, host);
if (access(path, F_OK) != SUCCESS) {
if ((rc = mkdir(path, mode)) != SUCCESS) {
printf("%s: mkdir: %s\n", __func__, strerror(errno));
printf("Error. Unable to create host directory %s.\n%s: mkdir: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
}
Expand All @@ -338,15 +338,15 @@ int nvmet_export_volume(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigne
if (access(path2, F_OK) != SUCCESS) {
rc = symlink(path, path2);
if (rc != SUCCESS) {
printf("%s: symlink: %s\n", __func__, strerror(errno));
printf("Error. Unable to link host to port.\n%s: symlink: %s\n", __func__, strerror(errno));
return rc;
}
}

/* Make sure that no other hosts can access the target */
sprintf(path, "%s/%s%s-%s/attr_allow_any_host", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if((fp = fopen(path, "w")) == NULL){
printf("%s: fopen: %s\n", __func__, strerror(errno));
printf("Error. Unable to open %s.\n%s: fopen: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
fprintf(fp, "0");
Expand All @@ -357,15 +357,15 @@ int nvmet_export_volume(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigne
sprintf(path, "%s/%s%s-%s/namespaces/1", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if (access(path, F_OK) != SUCCESS) {
if ((rc = mkdir(path, mode)) != SUCCESS) {
printf("%s: mkdir: %s\n", __func__, strerror(errno));
printf("Error. Unable to create namespace directory %s\n.%s: mkdir: %s\n", path, __func__, strerror(errno));
return rc;
}
}

/* Set device */
sprintf(path, "%s/%s%s-%s/namespaces/1/device_path", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if((fp = fopen(path, "w")) == NULL){
printf("%s: fopen: %s\n", __func__, strerror(errno));
printf("Error. Unable to open device_path file: %s\n%s: fopen: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
if (strncmp(device, "rd", 2) == SUCCESS)
Expand All @@ -377,7 +377,7 @@ int nvmet_export_volume(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigne
/* Enable volume */
sprintf(path, "%s/%s%s-%s/namespaces/1/enable", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if((fp = fopen(path, "w")) == NULL){
printf("%s: fopen: %s\n", __func__, strerror(errno));
printf("Error. Unable to open namespace enable file %s.\n%s: fopen: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
fprintf(fp, "1");
Expand All @@ -390,7 +390,7 @@ int nvmet_export_volume(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigne
if (access(path2, F_OK) != SUCCESS) {
rc = symlink(path, path2);
if (rc != SUCCESS) {
printf("%s: symlink: %s\n", __func__, strerror(errno));
printf("Error. Unable to create link of NQN to port.\n%s: symlink: %s\n", __func__, strerror(errno));
return rc;
}
}
Expand All @@ -407,7 +407,7 @@ int nvmet_export_volume(struct RD_PROFILE *rd_prof, RC_PROFILE *rc_prof, unsigne
if (access(path2, F_OK) != SUCCESS) {
rc = symlink(path, path2);
if (rc != SUCCESS) {
printf("%s: symlink: %s\n", __func__, strerror(errno));
printf("Error. Unable to create link of NQN to port.\n%s: symlink: %s\n", __func__, strerror(errno));
return rc;
}
}
Expand Down Expand Up @@ -451,7 +451,7 @@ int nvmet_unexport_volume(unsigned char *device, unsigned char *host, int port)
/* Make sure that no other namespaces exist. We do not create anything higher than 1. */
sprintf(path, "%s/%s%s-%s/namespaces/", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if ((err = scandir(path, &list, NULL, NULL)) < 0) {
printf("%s: scandir: %s\n", __func__, strerror(errno));
printf("Error. Unable to access %s.\n%s: scandir: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
for (n = 0; n < err; n++) if (list[n] != NULL) free(list[n]); /* clear list */
Expand All @@ -465,7 +465,7 @@ int nvmet_unexport_volume(unsigned char *device, unsigned char *host, int port)
if (access(path, F_OK) == SUCCESS) {
rc = unlink(path);
if (rc != SUCCESS) {
printf("%s: unlink: %s\n", __func__, strerror(errno));
printf("Error. Unable to remove host.\n%s: unlink: %s\n", __func__, strerror(errno));
return rc;
}
printf("Block device %s has been unmapped from NVMe Target host %s.\n", device, host);
Expand All @@ -488,7 +488,7 @@ int nvmet_unexport_volume(unsigned char *device, unsigned char *host, int port)
if (access(path, F_OK) == SUCCESS) {
rc = unlink(path);
if (rc != SUCCESS) {
printf("%s: unlink: %s\n", __func__, strerror(errno));
printf("Error. Unable to remove hosts.\n%s: unlink: %s\n", __func__, strerror(errno));
return rc;
}
}
Expand All @@ -505,7 +505,7 @@ int nvmet_unexport_volume(unsigned char *device, unsigned char *host, int port)
if (access(path, F_OK) == SUCCESS) {
rc = unlink(path);
if (rc != SUCCESS) {
printf("%s: unlink: %s\n", __func__, strerror(errno));
printf("Error. Unable to remove NQN from port.\n%s: unlink: %s\n", __func__, strerror(errno));
return rc;
}
printf("Block device %s has been unmapped from NVMe Target port %d.\n", device, port);
Expand All @@ -524,7 +524,7 @@ int nvmet_unexport_volume(unsigned char *device, unsigned char *host, int port)
if (access(path, F_OK) == SUCCESS) {
rc = unlink(path);
if (rc != SUCCESS) {
printf("%s: unlink: %s\n", __func__, strerror(errno));
printf("Error. Unable to remove NQN from ports.\n%s: unlink: %s\n", __func__, strerror(errno));
return rc;
}
}
Expand All @@ -542,7 +542,7 @@ int nvmet_unexport_volume(unsigned char *device, unsigned char *host, int port)
/* Disable volume */
sprintf(path, "%s/%s%s-%s/namespaces/1/enable", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if((fp = fopen(path, "w")) == NULL){
printf("%s: fopen: %s\n", __func__, strerror(errno));
printf("Error. Unable to open namespace enable file %s.\n%s: fopen: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
fprintf(fp, "0");
Expand All @@ -552,7 +552,7 @@ int nvmet_unexport_volume(unsigned char *device, unsigned char *host, int port)
sprintf(path, "%s/%s%s-%s/namespaces/1", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if (access(path, F_OK) == SUCCESS) {
if ((rc = rmdir(path)) != SUCCESS) {
printf("%s: rmdir: %s\n", __func__, strerror(errno));
printf("Error. Unable to remove namespace %s.\n%s: rmdir: %s\n", path, __func__, strerror(errno));
return rc;
}
}
Expand All @@ -561,7 +561,7 @@ int nvmet_unexport_volume(unsigned char *device, unsigned char *host, int port)
sprintf(path, "%s/%s%s-%s", SYS_NVMET_TGT, NQN_HDR_STR, hostname, device);
if (access(path, F_OK) == SUCCESS) {
if ((rc = rmdir(path)) != SUCCESS) {
printf("%s: rmdir: %s\n", __func__, strerror(errno));
printf("Error. Unable to remove NQN from NVMe Target subsystem %s.\n%s: rmdir: %s\n", path, __func__, strerror(errno));
return rc;
}
}
Expand Down Expand Up @@ -706,21 +706,21 @@ int nvmet_enable_port(unsigned char *interface, int port, int protocol)
}

if ((rc = mkdir(path, mode)) != SUCCESS) {
printf("%s: mkdir: %s\n", __func__, strerror(errno));
printf("Error. Unable to create port directory.\n%s: mkdir: %s\n", __func__, strerror(errno));
return INVALID_VALUE;
}

sprintf(path, "%s/%d/addr_trsvcid", SYS_NVMET_PORTS, port);
if((fp = fopen(path, "w")) == NULL){
printf("%s: fopen: %s\n", __func__, strerror(errno));
printf("Error. Unable to open %s.\n%s: fopen: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
fprintf(fp, "4420");
fclose(fp);

sprintf(path, "%s/%d/addr_adrfam", SYS_NVMET_PORTS, port);
if((fp = fopen(path, "w")) == NULL){
printf("%s: fopen: %s\n", __func__, strerror(errno));
printf("Error. Unable to open %s.\n%s: fopen: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
fprintf(fp, "ipv4");
Expand All @@ -732,15 +732,15 @@ int nvmet_enable_port(unsigned char *interface, int port, int protocol)
sprintf(proto, "tcp");
sprintf(path, "%s/%d/addr_trtype", SYS_NVMET_PORTS, port);
if((fp = fopen(path, "w")) == NULL){
printf("%s: fopen: %s\n", __func__, strerror(errno));
printf("Error. Unable to open %s.\n%s: fopen: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
fprintf(fp, "%s", proto);
fclose(fp);

sprintf(path, "%s/%d/addr_traddr", SYS_NVMET_PORTS, port);
if((fp = fopen(path, "w")) == NULL){
printf("%s: fopen: %s\n", __func__, strerror(errno));
printf("Error. Unable to open %s.\n%s: fopen: %s\n", path, __func__, strerror(errno));
return INVALID_VALUE;
}
fprintf(fp, "%s", ip);
Expand All @@ -766,7 +766,7 @@ int nvmet_disable_port(int port)
/* Make sure that no subsystems are mapped from this port. */
sprintf(path, "%s/%d/subsystems/", SYS_NVMET_PORTS, port);
if ((err = scandir(path, &list, NULL, NULL)) < 0) {
printf("%s: scandir: %s\n", __func__, strerror(errno));
printf("Error. Unable to access %s.\n%s: scandir: %s\n", path, __func__, strerror(errno));
return rc;
}
for (n = 0; n < err; n++) if (list[n] != NULL) free(list[n]); /* clear list */
Expand All @@ -778,7 +778,7 @@ int nvmet_disable_port(int port)
/* Remove the port */
sprintf(path, "%s/%d", SYS_NVMET_PORTS, port);
if ((rc = rmdir(path)) != SUCCESS) {
printf("%s: rmdir: %s\n", __func__, strerror(errno));
printf("Error. Unable to remove port.\n%s: rmdir: %s\n", __func__, strerror(errno));
return rc;
}

Expand Down

0 comments on commit b3f0683

Please sign in to comment.