From a1acc1bc780caca5c18820701ac10903deb2c129 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Tue, 17 Mar 2009 18:07:36 +0000 Subject: [PATCH] - scst_user docs updated - Added notification about device change in fileio_tgt git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@700 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- doc/scst_user_spec.txt | 14 ++++++++++++++ usr/fileio/common.c | 6 +++++- usr/fileio/fileio.c | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/doc/scst_user_spec.txt b/doc/scst_user_spec.txt index 2a1d51967..a7e0e369f 100644 --- a/doc/scst_user_spec.txt +++ b/doc/scst_user_spec.txt @@ -829,6 +829,20 @@ SCST_USER_FLUSH_CACHE returns 0 on success or -1 in case of error, and errno is set appropriately. + 7. SCST_USER_DEVICE_CAPACITY_CHANGED + +SCST_USER_DEVICE_CAPACITY_CHANGED - queues CAPACITY DATA HAS CHANGED +Unit Attention or corresponding Asynchronous Event to the corresponding +virtual device. It will notify remote initiators, connected to the +device, and allow them to automatically refresh new device size. You +should use SCST_USER_DEVICE_CAPACITY_CHANGED after resize of the device. + +SCST_USER_DEVICE_CAPACITY_CHANGED doesn't have any parameters. + +SCST_USER_DEVICE_CAPACITY_CHANGED returns 0 on success or -1 in case of +error, and errno is set appropriately. + + IV. Commands processing flow example. As the example consider a simple synchronous VTL, which serves one diff --git a/usr/fileio/common.c b/usr/fileio/common.c index 67619d719..3111fb6ae 100644 --- a/usr/fileio/common.c +++ b/usr/fileio/common.c @@ -125,14 +125,18 @@ static inline void set_cmd_error_status(struct scst_user_scsi_cmd_reply_exec *re static int set_sense(uint8_t *buffer, int len, int key, int asc, int ascq) { - int res = 14; + int res = SCST_STANDARD_SENSE_LEN; + EXTRACHECKS_BUG_ON(len < res); + memset(buffer, 0, res); + buffer[0] = 0x70; /* Error Code */ buffer[2] = key; /* Sense Key */ buffer[7] = 0x0a; /* Additional Sense Length */ buffer[12] = asc; /* ASC */ buffer[13] = ascq; /* ASCQ */ + TRACE_BUFFER("Sense set", buffer, res); return res; } diff --git a/usr/fileio/fileio.c b/usr/fileio/fileio.c index b04cbf85f..a902d6c01 100644 --- a/usr/fileio/fileio.c +++ b/usr/fileio/fileio.c @@ -189,6 +189,28 @@ out: return; } +void sigusr1_handler(int signo) +{ + int res; + + TRACE_ENTRY(); + + TRACE_MGMT_DBG("%s", "Capacity data changed..."); + + res = ioctl(dev.scst_usr_fd, SCST_USER_DEVICE_CAPACITY_CHANGED, NULL); + if (res != 0) { + res = errno; + PRINT_ERROR("Capacity data changed failed: %s", strerror(res)); + goto out; + } + + TRACE_DBG("%s", "Capacity data changed done."); + +out: + TRACE_EXIT(); + return; +} + int main(int argc, char **argv) { int res = 0; @@ -480,6 +502,19 @@ int main(int argc, char **argv) pthread_t thread[threads]; int i, j, rc; void *rc1; + struct sigaction act; + + memset(&act, 0, sizeof(act)); + act.sa_handler = sigusr1_handler; + act.sa_flags = SA_RESTART; + sigemptyset(&act.sa_mask); + res = sigaction(SIGUSR1, &act, NULL); + if (res != 0) { + res = errno; + PRINT_ERROR("sigaction() failed: %s", + strerror(res)); + /* don't do anything */ + } for(i = 0; i < threads; i++) { rc = pthread_create(&thread[i], NULL, main_loop, &dev); @@ -492,8 +527,6 @@ int main(int argc, char **argv) } if (flush_interval != 0) { - struct sigaction act; - memset(&act, 0, sizeof(act)); act.sa_handler = sigalrm_handler; act.sa_flags = SA_RESTART;