Tomo, Please find attached a patch for the fix that Daisuke Fujita showed below regards ronnie sahlberg On Fri, Jun 3, 2011 at 3:17 PM, FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx> wrote: > On Thu, 02 Jun 2011 21:23:23 +0900 > Daisuke Fujita <fuzita.daisuke@xxxxxxxxxxxxxx> wrote: > >> Dear developers, >> >> I got the "tgtadm: invalid request" message when I executed the >> following command. >> >> # tgtadm --lld iscsi --op new --mode logicalunit --tid=1 --lun 1 -b >> /media/CentOS_5.4_Final/RELEASE-NOTES-en.html >> tgtadm: invalid request >> # tail /var/log/messages >> Jun 2 20:52:58 cent_54_agt_fu2 tgtd: backed_file_open(92) Could not open >> /media/CentOS_5.4_Final/RELEASE-NOTES-en.html, Read-only file system >> >> I think that "backed_file_open" method may return with EROFS in addition >> to EACCES so tgtd should handle it. What do you think? >> >> EROFS pathname refers to a file on a read-only filesystem and write >> access was requested. >> >> Reference: >> - bstype = rdwr (usr/bs_rdwr.c) >> static int bs_rdwr_open(struct scsi_lu *lu, char *path, int *fd, uint64_t >> *size) >> { >> *fd = backed_file_open(path, O_RDWR|O_LARGEFILE|lu->bsoflags, size); >> /* If we get access denied, try opening the file in readonly mode */ >> if (*fd == -1 && errno == EACCES) { >> *fd = backed_file_open(path, >> O_RDONLY|O_LARGEFILE|lu->bsoflags, >> size); >> lu->attrs.readonly = 1; >> } >> if (*fd < 0) >> return *fd; >> >> return 0; >> } >> >> - bstype=aio (usr/bs_aio.c) >> static int bs_aio_open(struct scsi_lu *lu, char *path, int *fd, uint64_t >> *size) >> { >> *fd = backed_file_open(path, O_RDWR|O_LARGEFILE|O_DIRECT, size); >> /* If we get access denied, try opening the file in readonly mode */ >> if (*fd == -1 && errno == EACCES) { >> *fd = backed_file_open(path, O_RDONLY|O_LARGEFILE|O_DIRECT, >> size); >> lu->attrs.readonly = 1; >> } >> if (*fd < 0) >> return *fd; >> return 0; >> } >> >> When I changed the condition "if (*fd == -1 && errno == EACCES)" to >> "if (*fd == -1 && (errno == EACCES || errno == EROFS))", it works as >> I expected. > > Thanks, the fix sounds good to me. > > Can you send a patch? > -- > To unsubscribe from this list: send the line "unsubscribe stgt" in > the body of a message to majordomo@xxxxxxxxxxxxxxx > More majordomo info at http://vger.kernel.org/majordomo-info.html >
Attachment:
0001-Try-open-the-backing-file-as-readonly-if-the-initial.patch.gz
Description: GNU Zip compressed data
From d25685a909009e2f269980ba63428a93bf176f58 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx> Date: Fri, 3 Jun 2011 22:08:57 +1000 Subject: [PATCH] Try open the backing file as readonly if the initial open fails with EROFS Bug description and fix by fuzita.daisuke@xxxxxxxxxxxxxx Signed-off-by: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx> --- usr/bs_aio.c | 2 +- usr/bs_rdwr.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/bs_aio.c b/usr/bs_aio.c index ce56b68..7acbb75 100644 --- a/usr/bs_aio.c +++ b/usr/bs_aio.c @@ -114,7 +114,7 @@ static int bs_aio_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size) { *fd = backed_file_open(path, O_RDWR|O_LARGEFILE|O_DIRECT, size); /* If we get access denied, try opening the file in readonly mode */ - if (*fd == -1 && errno == EACCES) { + if (*fd == -1 && (errno == EACCES || errno == EROFS)) { *fd = backed_file_open(path, O_RDONLY|O_LARGEFILE|O_DIRECT, size); lu->attrs.readonly = 1; diff --git a/usr/bs_rdwr.c b/usr/bs_rdwr.c index 77d52e3..4003996 100644 --- a/usr/bs_rdwr.c +++ b/usr/bs_rdwr.c @@ -132,7 +132,7 @@ static int bs_rdwr_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size) { *fd = backed_file_open(path, O_RDWR|O_LARGEFILE|lu->bsoflags, size); /* If we get access denied, try opening the file in readonly mode */ - if (*fd == -1 && errno == EACCES) { + if (*fd == -1 && (errno == EACCES || errno == EROFS)) { *fd = backed_file_open(path, O_RDONLY|O_LARGEFILE|lu->bsoflags, size); lu->attrs.readonly = 1; -- 1.7.3.1