lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 24 Mar 2009 11:48:19 -0400 (EDT)
From:	Steven Rostedt <rostedt@...dmis.org>
To:	Li Zefan <lizf@...fujitsu.com>
cc:	Ingo Molnar <mingo@...e.hu>, Jens Axboe <jens.axboe@...cle.com>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Arnaldo Carvalho de Melo <acme@...hat.com>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 5/5] blktrace: print human-readable act_mask


On Tue, 24 Mar 2009, Li Zefan wrote:
> +static ssize_t blk_trace_mask2str(char *buf, int mask)
> +{
> +	int i;
> +	char *p = buf;
> +
> +	for (i = 0; i < ARRAY_SIZE(mask_maps); i++) {
> +		if (mask & mask_maps[i].mask) {
> +			p += sprintf(p, "%s%s",
> +				    (p == buf) ? "" : ",", mask_maps[i].str);
> +		}
> +	}
> +	*p++ = '\n';
> +
> +	return (p - buf);

The above is still simple, but if it starts to ge complex, you might want 
to convert it to the trace_seq functions. That can make moving to a buffer
easier.

#include "trace_output.h"

static bool blk_trace_mask2str(struct trace_seq *s, int mask)
{
	bool comma = false;
	int i;

	for (i = 0; i < ARRAY_SIZE(mask_maps); i++) {
		if (mask & mask_maps[i].mask) {
			trace_print_seq(s, "%s%s",
				comma ? "," : "",
				mask_maps[i].str);
			comma = 1;
		}
	}
}


	struct trace_seq *s;

	s = kmalloc(sizeof(*s), GFP_KERNEL);
	if (!s)
		do error;

	
	blk_trace_str2mask(s, mask);

This would put the data into s->buffer and have a length too.

Just letting you know about this. It may come in handy. Most of the code 
in kernel/trace*.c uses this.

-- Steve
	
	
> +}
> +
>  static struct request_queue *blk_trace_get_queue(struct block_device *bdev)
>  {
>  	if (bdev->bd_disk == NULL)
> @@ -1399,7 +1423,7 @@ static ssize_t sysfs_blk_trace_attr_show(struct device *dev,
>  	if (q->blk_trace == NULL)
>  		ret = sprintf(buf, "disabled\n");
>  	else if (attr == &dev_attr_act_mask)
> -		ret = sprintf(buf, "%#x\n", q->blk_trace->act_mask);
> +		ret = blk_trace_mask2str(buf, q->blk_trace->act_mask);
>  	else if (attr == &dev_attr_pid)
>  		ret = sprintf(buf, "%u\n", q->blk_trace->pid);
>  	else if (attr == &dev_attr_start_lba)
> @@ -1432,9 +1456,11 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
>  	if (attr == &dev_attr_act_mask) {
>  		if (sscanf(buf, "%llx", &value) != 1) {
>  			/* Assume it is a list of trace category names */
> -			value = blk_str2act_mask(buf);
> -			if (value < 0)
> +			value = blk_trace_str2mask(buf);
> +			if (value < 0) {
> +				ret = value;
>  				goto out;
> +			}
>  		}
>  	} else if (sscanf(buf, "%llu", &value) != 1)
>  		goto out;
> -- 
> 1.5.4.rc3
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ