Skip to content

Commit

Permalink
Handle write-perm on LOCATE correctly (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atsushi Abe committed Dec 9, 2020
1 parent 90a8b30 commit 303ca43
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions messages/internal_error/root.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ root:table {
I1198E:string{ "The tape is already removed." }
I1199E:string{ "You need to move tape to a storage slot first before the operation." }
I1200E:string{ "The operation needs to be started again." }
I1201E:string{ "Locate returns write-perm error." }

// Special error codes
I9997E:string{ "Child process error (ltfsck/mkltfs): %s (%d)." }
Expand Down
1 change: 1 addition & 0 deletions messages/libltfs/root.txt
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ v
17264I:string { "The index on %s is newer, but MAM shows a permanent write error happened on %s." }
17265I:string { "Skip writing the index because of %s." }
17266I:string { "Skip setting the append only mode because the drive doesn't seem to support it." }
17267E:string { "Locate command returns write-perm error (%d). Replace a return code to %d." }

// For Debug 19999I:string { "%s %s %d." }

Expand Down
1 change: 1 addition & 0 deletions src/libltfs/arch/errormap.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ static struct error_map fuse_error_list[] = {
{ LTFS_TAPE_REMOVED, "I1198E", EIDRM},
{ LTFS_NEED_MOVE, "I1199E", EINVAL},
{ LTFS_NEED_START_OVER, "I1200E", EINVAL},
{ LTFS_LOCATE_ERROR, "I1201E", EIO},

{ EDEV_NO_SENSE, "D0000E", EIO},
{ EDEV_OVERRUN, "D0002E", EIO},
Expand Down
1 change: 1 addition & 0 deletions src/libltfs/ltfs_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
#define LTFS_TAPE_REMOVED 1198 /* The tape is already removed */
#define LTFS_NEED_MOVE 1199 /* Need to move tape to a storage slot first before the operation */
#define LTFS_NEED_START_OVER 1200 /* Need operation needs to be started again */
#define LTFS_LOCATE_ERROR 1201 /* Locate returns write-perm error */

#define LTFS_ERR_MAX 19999

Expand Down
29 changes: 26 additions & 3 deletions src/libltfs/tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ int tape_seek_append_position(struct device_data *dev, tape_partition_t prt, boo
if (ret < 0) {
ltfsmsg(LTFS_ERR, 12033E, ret);
dev->write_error = true;

return ret;
}

Expand Down Expand Up @@ -996,7 +997,7 @@ int tape_rewind(struct device_data *dev)
*/
int tape_seek(struct device_data *dev, struct tc_position *pos)
{
int ret;
int ret = 0;

CHECK_ARG_NULL(dev, -LTFS_NULL_ARG);
CHECK_ARG_NULL(pos, -LTFS_NULL_ARG);
Expand All @@ -1016,8 +1017,14 @@ int tape_seek(struct device_data *dev, struct tc_position *pos)
ltfs_mutex_unlock(&dev->read_only_flag_mutex);
}
}
else {
ret = 0;

if (IS_WRITE_PERM(-ret)) {
/*
* LOCATE command must not return a WRITE_PERM related error.
* LOCATE is actually read operation, it doesn't make sense to return a WRITE_PERM at all.
*/
ltfsmsg(LTFS_ERR, 17267E, ret, -LTFS_LOCATE_ERROR);
ret = -LTFS_LOCATE_ERROR;
}

if (ret == 0 && (dev->position.partition != pos->partition ||
Expand Down Expand Up @@ -1051,6 +1058,14 @@ int tape_seek_eod(struct device_data *dev, tape_partition_t partition)
ret = dev->backend->locate(dev->backend_data, seekpos, &dev->position);
if (ret < 0) {
ltfsmsg(LTFS_ERR, 12039E, ret);
if (IS_WRITE_PERM(-ret)) {
/*
* LOCATE command must not return a WRITE_PERM related error.
* LOCATE is actually read operation, it doesn't make sense to return a WRITE_PERM at all.
*/
ltfsmsg(LTFS_ERR, 17267E, ret, -LTFS_LOCATE_ERROR);
ret = -LTFS_LOCATE_ERROR;
}
return ret;
}

Expand Down Expand Up @@ -1547,6 +1562,14 @@ int tape_unformat(struct device_data *dev)
ret = dev->backend->locate(dev->backend_data, bom, &dev->position);
if (ret < 0) {
ltfsmsg(LTFS_ERR, 12054E, ret);
if (IS_WRITE_PERM(-ret)) {
/*
* LOCATE command must not return a WRITE_PERM related error.
* LOCATE is actually read operation, it doesn't make sense to return a WRITE_PERM at all.
*/
ltfsmsg(LTFS_ERR, 17267E, ret, -LTFS_LOCATE_ERROR);
ret = -LTFS_LOCATE_ERROR;
}
return ret;
}

Expand Down

0 comments on commit 303ca43

Please sign in to comment.