@@ -1887,6 +1887,49 @@ static void p_stop(struct seq_file *m, void *p)
18871887 mutex_unlock (& event_mutex );
18881888}
18891889
1890+ /**
1891+ * event_enable_read - read from a trace event file to retrieve its status.
1892+ * @filp: file pointer associated with the target trace event.
1893+ * @ubuf: user space buffer where the event status is copied to.
1894+ * @cnt: number of bytes to be copied to the user space buffer.
1895+ * @ppos: the current position in the buffer.
1896+ *
1897+ * This is a way for user space executables to retrieve the status of a
1898+ * specific event
1899+ *
1900+ * Function's expectations:
1901+ * - The global event_mutex shall be taken before performing any operation
1902+ * on the target event;
1903+ *
1904+ * - The string copied to user space shall be formatted according to the
1905+ * status flags from the target event file:
1906+ * - If the enable flag is set AND the soft_disable flag is not set then
1907+ * the first character shall be set to "1" ELSE it shall be set to "0";
1908+ *
1909+ * - If either the soft_disable flag or the soft_mode flag is set then the
1910+ * second character shall be set to "*" ELSE it is skipped;
1911+ *
1912+ * - The string shall be terminated by a newline ("\n") and any remaining
1913+ * character shall be set to "0";
1914+ *
1915+ * - This function shall invoke simple_read_from_buffer() to perform the copy
1916+ * of the kernel space string to ubuf.
1917+ *
1918+ * Assumptions of Use:
1919+ * - The caller shall pass cnt equal or greater than the length of the string
1920+ * to be copied to user space;
1921+ *
1922+ * - Any read operation on a file descriptor, unless it is the first operation
1923+ * following a trace event file open, shall be preceded by an lseek
1924+ * invocation to reposition the file offset to zero.
1925+ *
1926+ * Context: process context, locks and unlocks event_mutex.
1927+ *
1928+ * Return:
1929+ * * the number of copied bytes on success
1930+ * * %-ENODEV - the event file cannot be retrieved from the input filp
1931+ * * any error returned by simple_read_from_buffer
1932+ */
18901933static ssize_t
18911934event_enable_read (struct file * filp , char __user * ubuf , size_t cnt ,
18921935 loff_t * ppos )
@@ -1916,6 +1959,47 @@ event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
19161959 return simple_read_from_buffer (ubuf , cnt , ppos , buf , strlen (buf ));
19171960}
19181961
1962+ /**
1963+ * event_enable_write - write to a trace event file to enable/disable it.
1964+ * @filp: file pointer associated with the target trace event.
1965+ * @ubuf: user space buffer where the enable/disable value is copied from.
1966+ * @cnt: number of bytes to be copied from the user space buffer.
1967+ * @ppos: the current position in the buffer.
1968+ *
1969+ * This is a way for user space executables to enable or disable event
1970+ * recording.
1971+ *
1972+ * Function's expectations:
1973+ * - This function shall copy cnt bytes from the input ubuf buffer to a kernel
1974+ * space buffer and shall convert the string within the kernel space buffer
1975+ * into a decimal base format number;
1976+ *
1977+ * - The global event_mutex shall be taken before performing any operation
1978+ * on the target event;
1979+ *
1980+ * - This function shall check the size of the per-cpu ring-buffers used for
1981+ * the event trace data and, if smaller than TRACE_BUF_SIZE_DEFAULT, expand
1982+ * them to TRACE_BUF_SIZE_DEFAULT bytes (sizes larger than
1983+ * TRACE_BUF_SIZE_DEFAULT are not allowed);
1984+ *
1985+ * - This function shall invoke ftrace_event_enable_disable to enable or
1986+ * disable the target trace event according to the value read from user space
1987+ * (0 - disable, 1 - enable);
1988+ *
1989+ * - This function shall increase the file position pointed by ppos by the
1990+ * number of bytes specified by cnt.
1991+ *
1992+ * Context: process context, locks and unlocks event_mutex.
1993+ *
1994+ * Return:
1995+ * * the number of written bytes on success
1996+ * * any error returned by kstrtoul_from_user
1997+ * * %-ENODEV - the event file cannot be retrieved from the input filp
1998+ * * any error returned by tracing_update_buffers
1999+ * * any error returned by ftrace_event_enable_disable
2000+ * * %-EINVAL - the value copied from the user space ubuf is different
2001+ * from 0 or 1
2002+ */
19192003static ssize_t
19202004event_enable_write (struct file * filp , const char __user * ubuf , size_t cnt ,
19212005 loff_t * ppos )
0 commit comments