summaryrefslogtreecommitdiffstats
path: root/sys/cam
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2017-01-26 20:51:50 +0000
committermav <mav@FreeBSD.org>2017-01-26 20:51:50 +0000
commit961ed0497f3e25ba03cee5f8b23a4f71b0367b86 (patch)
treee8c4b3ecd7ccd48197334aad22064a3e70464864 /sys/cam
parentdf3230815c4fd7950d80095e4319eb1165b9e0a9 (diff)
downloadFreeBSD-src-961ed0497f3e25ba03cee5f8b23a4f71b0367b86.zip
FreeBSD-src-961ed0497f3e25ba03cee5f8b23a4f71b0367b86.tar.gz
MFC r311680: Make CTL_GETSTATS ioctl return partial data if buffer is small.
Diffstat (limited to 'sys/cam')
-rw-r--r--sys/cam/ctl/ctl.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c
index 50565a5..a7444b6 100644
--- a/sys/cam/ctl/ctl.c
+++ b/sys/cam/ctl/ctl.c
@@ -2770,32 +2770,29 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
break;
}
case CTL_GETSTATS: {
- struct ctl_stats *stats;
+ struct ctl_stats *stats = (struct ctl_stats *)addr;
int i;
- stats = (struct ctl_stats *)addr;
-
- if ((sizeof(struct ctl_lun_io_stats) * softc->num_luns) >
- stats->alloc_len) {
- stats->status = CTL_SS_NEED_MORE_SPACE;
- stats->num_luns = softc->num_luns;
- break;
- }
/*
* XXX KDM no locking here. If the LUN list changes,
* things can blow up.
*/
i = 0;
+ stats->status = CTL_SS_OK;
+ stats->fill_len = 0;
STAILQ_FOREACH(lun, &softc->lun_list, links) {
+ if (stats->fill_len + sizeof(lun->stats) >
+ stats->alloc_len) {
+ stats->status = CTL_SS_NEED_MORE_SPACE;
+ break;
+ }
retval = copyout(&lun->stats, &stats->lun_stats[i++],
sizeof(lun->stats));
if (retval != 0)
break;
+ stats->fill_len += sizeof(lun->stats);
}
stats->num_luns = softc->num_luns;
- stats->fill_len = sizeof(struct ctl_lun_io_stats) *
- softc->num_luns;
- stats->status = CTL_SS_OK;
#ifdef CTL_TIME_IO
stats->flags = CTL_STATS_FLAG_TIME_VALID;
#else
OpenPOWER on IntegriCloud