On Sun, 22 Mar 2009 15:34:01 +0000 Chris Webb <chris@xxxxxxxxxxxx> wrote: > I'm trying to disable write-caching for devices exported via iSCSI by tgtd > 0.9.5. According to > > http://lists.wpkg.org/pipermail/stgt/2008-June/001699.html > > I should be able to do this with > > tgtadm -L iscsi -m logicalunit -o update -t $TID -l $LUN \ > -P mode_page=8:0:18:0x10:0:0xff:0xff:0:0:0xff:0xff:0xff:0xff:0x80:0x14:0:0:0:0:0:0 > > (Both of the patches listed seem already to be in the newly released tgtd > 0.9.5.) > > However, despite having run this for the LUN concerned before logging in to > it with an initiator, I'm still getting uncached writes (far too fast for > the underlying disk) when I do an O_SYNC/O_DIRECT write to the /dev/sdX on a > remote machine. O_DIRECT/O_SYNC writes to the local block device run at the > expected speed, of course. My sequence of commands to export looks like > > tgtadm -L iscsi -m target -o new -t $TID -T $TARGET > tgtadm -L iscsi -m logicalunit -o new -t $TID -l 1 -b $DEVICE > tgtadm -L iscsi -m logicalunit -o update -t $TID -l 1 > -P mode_page=8:0:18:0x10:0:0xff:0xff:0:0:0xff:0xff:0xff:0xff:0x80:0x14:0:0:0:0:0:0 > tgtadm -L iscsi -m account -o bind -t $TID -u $USER > tgtadm -L iscsi -m target -o bind -t $TID -I ALL > > and everything is apparently working fine apart from the unwanted write > caching. > > I'm testing using tgtd 0.9.5 with the kernel target driver from stock linux > 2.6.28.2 (amd64). My initiator is also linux: iscsi_tcp from 2.6.28.2. Any > suggestions as to what I'm doing wrong would be greatly appreciated. Seems that we misuse sync_file_range. Can you please try this? diff --git a/usr/bs_mmap.c b/usr/bs_mmap.c index bb24f5e..b62c8e6 100644 --- a/usr/bs_mmap.c +++ b/usr/bs_mmap.c @@ -57,10 +57,7 @@ static void bs_mmap_request(struct scsi_cmd *cmd) key = ILLEGAL_REQUEST; asc = ASC_INVALID_FIELD_IN_CDB; } else { - unsigned int flags = - SYNC_FILE_RANGE_WAIT_BEFORE| SYNC_FILE_RANGE_WRITE; - - ret = __sync_file_range(cmd->dev->fd, cmd->offset, length, flags); + ret = __sync_file_range(cmd->dev->fd, cmd->offset, length); if (ret) { result = SAM_STAT_CHECK_CONDITION; key = MEDIUM_ERROR; diff --git a/usr/bs_rdwr.c b/usr/bs_rdwr.c index 65a6136..6068479 100644 --- a/usr/bs_rdwr.c +++ b/usr/bs_rdwr.c @@ -49,9 +49,8 @@ static void bs_sync_sync_range(struct scsi_cmd *cmd, uint32_t length, int *result, uint8_t *key, uint16_t *asc) { int ret; - unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE| SYNC_FILE_RANGE_WRITE; - ret = __sync_file_range(cmd->dev->fd, cmd->offset, length, flags); + ret = __sync_file_range(cmd->dev->fd, cmd->offset, length); if (ret) set_medium_error(result, key, asc); } diff --git a/usr/util.h b/usr/util.h index 794c70b..49d980d 100644 --- a/usr/util.h +++ b/usr/util.h @@ -119,13 +119,14 @@ extern unsigned long pagesize, pageshift; extern long int syscall(long int sysno, ...); -static inline int __sync_file_range(int fd, __off64_t offset, __off64_t bytes, - unsigned int flags) +static inline int __sync_file_range(int fd, __off64_t offset, __off64_t bytes) { int ret; + unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE + | SYNC_FILE_RANGE_WAIT_AFTER; ret = syscall(__NR_sync_file_range, fd, offset, bytes, flags); - if (ret == -EPERM) + if (ret) ret = fsync(fd); return ret; } -- 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