Re: [RFC PATCH] libtracefs: Add more methods for writing to files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 12 Apr 2021 18:20:06 +0300
"Yordan Karadzhov (VMware)" <y.karadz@xxxxxxxxx> wrote:

> @@ -364,19 +384,34 @@ static int write_file(const char *file, const char *str)
>  int tracefs_instance_file_write(struct tracefs_instance *instance,
>  				 const char *file, const char *str)
>  {
> -	struct stat st;
> -	char *path;
> -	int ret;
> +	return instance_file_write(instance, file, str, O_WRONLY | O_TRUNC);
> +}
>  
> -	path = tracefs_instance_get_file(instance, file);
> -	if (!path)
> -		return -1;
> -	ret = stat(path, &st);
> -	if (ret == 0)
> -		ret = write_file(path, str);
> -	tracefs_put_tracing_file(path);
> +/**
> + * tracefs_instance_file_write - Append to a trace file of specific instance.

I think you meant "tracefs_instance_file_append - "

> + * @instance: ftrace instance, can be NULL for the top instance
> + * @file: name of the file
> + * @str: nul terminated string, that will be appended to the file.
> + *
> + * Returns the number of appended bytes, or -1 in case of an error.
> + */
> +int tracefs_instance_file_append(struct tracefs_instance *instance,
> +				 const char *file, const char *str)
> +{
> +	return instance_file_write(instance, file, str, O_WRONLY);
> +}
>  
> -	return ret;
> +/**
> + * tracefs_instance_file_write - Clear a trace file of specific instance.

And "tracefs_instance_file_clear - "

> + * @instance: ftrace instance, can be NULL for the top instance
> + * @file: name of the file

 "of the file to clear"

More comments should be in the body.

"Used to clear the file. Note, it only opens with O_TRUNC and closes the
file. If the file has content that does not get cleared in this way, this
will not have any effect. For example, set_ftrace_filter can have probes
that are not cleared by O_TRUNC:

  echo "schedule:stacktrace" > set_ftrace_filter

This function will not clear the above "set_ftrace_filter" after that
command."


> + *
> + * Returns 0 on success, or -1 in case of an error.
> + */
> +int tracefs_instance_file_clear(struct tracefs_instance *instance,
> +				const char *file)
> +{
> +	return instance_file_write(instance, file, NULL, O_WRONLY | O_TRUNC);
>  }
>  
>  /**

Other than that, it looks good.

-- Steve



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux