[patch] SG_IO ioctl

Dmitry V. Levin ldv at altlinux.org
Thu Mar 15 01:11:11 UTC 2007


Hi,

On Tue, Mar 13, 2007 at 02:00:54PM +0100, Vladimir Nadvornik wrote:
[...]
> This patch adds possibility to trace linux SG_IO ioctl arguments and results.
> Do you think it can be included? 

Yes, probably with minor adjustments.

> I'm looking forward for your feedback (please keep me in cc, as I am not 
> subscribed).

OK

[...]
> +static void
> +print_sg_io_direction(int dir)
> +{
> +	switch (dir) {
> +	case SG_DXFER_NONE:
> +		tprintf("SG_DXFER_NONE");
> +		break;
> +	case SG_DXFER_TO_DEV:
> +		tprintf("SG_DXFER_TO_DEV");
> +		break;
> +	case SG_DXFER_FROM_DEV:
> +		tprintf("SG_DXFER_FROM_DEV");
> +		break;
> +	case SG_DXFER_TO_FROM_DEV:
> +		tprintf("SG_DXFER_TO_FROM_DEV");
> +		break;
> +	default:
> +		tprintf("dxfer_direction=%d", dir);
> +		break;
> +	}
> +}

strace coding tradition for such parsers is to create
static const struct xlat sg_io_dxfer[]
and use
printxval(sg_io_dxfer, dir, "SG_DXFER_???");
instead of homebrew print_sg_io_direction() function.

[...]
> +	cmd = (unsigned char *) malloc(sg_io->cmd_len);
> +	if (cmd) {
> +		if (umoven(tcp, (unsigned long)sg_io->cmdp, sg_io->cmd_len, cmd) >= 0)
> +			print_sg_io_buffer(sg_io->cmd_len, cmd);
> +		free(cmd);
> +	}

If umoven() call fails, smth like
tprintf("%#lx", sg_io->cmdp)
need to be done.

> +	sb = (unsigned char *) malloc(sg_io->sb_len_wr);
> +	if (sb) {
> +		if (umoven(tcp, (unsigned long)sg_io->sbp, sg_io->sb_len_wr, sb) >= 0)
> +			print_sg_io_buffer(sg_io->sb_len_wr, sb);
> +		free(sb);
> +	}

Likewise.

> +int
> +scsi_ioctl(tcp, code, arg)

Btw, why scsi_ioctl?  Isn't it just scsi sg_io ioctl parser?

> +		if (exiting(tcp)) {
> +			struct sg_io_hdr sg_io;
> +			if (umove(tcp, arg, &sg_io) >= 0) {
> +				print_sg_io_res(tcp, &sg_io);
> +			}
> +		}

Looks like syserror(tcp) check is missing here.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20070315/ba84ef81/attachment.bin>


More information about the Strace-devel mailing list