Skip to content

Commit

Permalink
[S390] Add debug_register_mode() function to debug feature API
Browse files Browse the repository at this point in the history
The new function supports setting of permissions for the debugfs files
created by the debug feature. In addition to that, the function provides
uid and gid as parameters for future use. Currently only root is allowed
for uid and gid.

Signed-off-by: Michael Holzheu <[email protected]>
Signed-off-by: Martin Schwidefsky <[email protected]>
Signed-off-by: Heiko Carstens <[email protected]>
  • Loading branch information
Michael Holzheu authored and heicarst committed Apr 17, 2008
1 parent 9f7819c commit 9637c3f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
21 changes: 21 additions & 0 deletions Documentation/s390/s390dbf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ Return Value: Handle for generated debug area
Description: Allocates memory for a debug log
Must not be called within an interrupt handler

----------------------------------------------------------------------------
debug_info_t *debug_register_mode(char *name, int pages, int nr_areas,
int buf_size, mode_t mode, uid_t uid,
gid_t gid);

Parameter: name: Name of debug log (e.g. used for debugfs entry)
pages: Number of pages, which will be allocated per area
nr_areas: Number of debug areas
buf_size: Size of data area in each debug entry
mode: File mode for debugfs files. E.g. S_IRWXUGO
uid: User ID for debugfs files. Currently only 0 is
supported.
gid: Group ID for debugfs files. Currently only 0 is
supported.

Return Value: Handle for generated debug area
NULL if register failed

Description: Allocates memory for a debug log
Must not be called within an interrupt handler

---------------------------------------------------------------------------
void debug_unregister (debug_info_t * id);

Expand Down
51 changes: 38 additions & 13 deletions arch/s390/kernel/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static ssize_t debug_input(struct file *file, const char __user *user_buf,
static int debug_open(struct inode *inode, struct file *file);
static int debug_close(struct inode *inode, struct file *file);
static debug_info_t* debug_info_create(char *name, int pages_per_area,
int nr_areas, int buf_size);
int nr_areas, int buf_size, mode_t mode);
static void debug_info_get(debug_info_t *);
static void debug_info_put(debug_info_t *);
static int debug_prolog_level_fn(debug_info_t * id,
Expand Down Expand Up @@ -327,7 +327,8 @@ debug_info_free(debug_info_t* db_info){
*/

static debug_info_t*
debug_info_create(char *name, int pages_per_area, int nr_areas, int buf_size)
debug_info_create(char *name, int pages_per_area, int nr_areas, int buf_size,
mode_t mode)
{
debug_info_t* rc;

Expand All @@ -336,6 +337,8 @@ debug_info_create(char *name, int pages_per_area, int nr_areas, int buf_size)
if(!rc)
goto out;

rc->mode = mode & ~S_IFMT;

/* create root directory */
rc->debugfs_root_entry = debugfs_create_dir(rc->name,
debug_debugfs_root_entry);
Expand Down Expand Up @@ -676,23 +679,30 @@ debug_close(struct inode *inode, struct file *file)
}

/*
* debug_register:
* - creates and initializes debug area for the caller
* - returns handle for debug area
* debug_register_mode:
* - Creates and initializes debug area for the caller
* The mode parameter allows to specify access rights for the s390dbf files
* - Returns handle for debug area
*/

debug_info_t*
debug_register (char *name, int pages_per_area, int nr_areas, int buf_size)
debug_info_t *debug_register_mode(char *name, int pages_per_area, int nr_areas,
int buf_size, mode_t mode, uid_t uid,
gid_t gid)
{
debug_info_t *rc = NULL;

/* Since debugfs currently does not support uid/gid other than root, */
/* we do not allow gid/uid != 0 until we get support for that. */
if ((uid != 0) || (gid != 0))
printk(KERN_WARNING "debug: Warning - Currently only uid/gid "
"= 0 are supported. Using root as owner now!");
if (!initialized)
BUG();
mutex_lock(&debug_mutex);

/* create new debug_info */

rc = debug_info_create(name, pages_per_area, nr_areas, buf_size);
rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode);
if(!rc)
goto out;
debug_register_view(rc, &debug_level_view);
Expand All @@ -705,6 +715,20 @@ debug_register (char *name, int pages_per_area, int nr_areas, int buf_size)
mutex_unlock(&debug_mutex);
return rc;
}
EXPORT_SYMBOL(debug_register_mode);

/*
* debug_register:
* - creates and initializes debug area for the caller
* - returns handle for debug area
*/

debug_info_t *debug_register(char *name, int pages_per_area, int nr_areas,
int buf_size)
{
return debug_register_mode(name, pages_per_area, nr_areas, buf_size,
S_IRUSR | S_IWUSR, 0, 0);
}

/*
* debug_unregister:
Expand Down Expand Up @@ -1073,15 +1097,16 @@ debug_register_view(debug_info_t * id, struct debug_view *view)
int rc = 0;
int i;
unsigned long flags;
mode_t mode = S_IFREG;
mode_t mode;
struct dentry *pde;

if (!id)
goto out;
if (view->prolog_proc || view->format_proc || view->header_proc)
mode |= S_IRUSR;
if (view->input_proc)
mode |= S_IWUSR;
mode = (id->mode | S_IFREG) & ~S_IXUGO;
if (!(view->prolog_proc || view->format_proc || view->header_proc))
mode &= ~(S_IRUSR | S_IRGRP | S_IROTH);
if (!view->input_proc)
mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
pde = debugfs_create_file(view->name, mode, id->debugfs_root_entry,
id , &debug_file_ops);
if (!pde){
Expand Down
5 changes: 5 additions & 0 deletions include/asm-s390/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef struct debug_info {
struct dentry* debugfs_entries[DEBUG_MAX_VIEWS];
struct debug_view* views[DEBUG_MAX_VIEWS];
char name[DEBUG_MAX_NAME_LEN];
mode_t mode;
} debug_info_t;

typedef int (debug_header_proc_t) (debug_info_t* id,
Expand Down Expand Up @@ -122,6 +123,10 @@ debug_entry_t* debug_exception_common(debug_info_t* id, int level,
debug_info_t* debug_register(char* name, int pages, int nr_areas,
int buf_size);

debug_info_t *debug_register_mode(char *name, int pages, int nr_areas,
int buf_size, mode_t mode, uid_t uid,
gid_t gid);

void debug_unregister(debug_info_t* id);

void debug_set_level(debug_info_t* id, int new_level);
Expand Down

0 comments on commit 9637c3f

Please sign in to comment.