[Crash-utility] Support for namespaces in mount (option -n)

Olivier Daudel olivier.daudel at u-paris10.fr
Thu Sep 7 20:46:07 UTC 2006


Hi Dave,
This patch try to support namespaces.
The following sample use two processes having different namespaces.
For example, /sys and /dev/shm are presents in one namespace and not in 
the other.
Olivier.

crash> mount -n 1
VFSMOUNT SUPERBLK TYPE   DEVNAME            DIRNAME
f7eab780 f7eaf200 rootfs rootfs             /         f7eabf00 f784d800 
tmpfs  /dev               /dev      f7eab080 f7ce5600 ext3   /dev/root  
         /         f7eabf80 f7ea3c00 proc   /proc              /proc    
  f7eab100 f7a7ae00 usbfs  /proc/bus/usb      /proc/bus/usb
f7eab880 f7eaf400 sysfs  /sys               /sys      f7eab980 f7d72200 
devpts /dev/devpts        /dev/pts  f7eaba80 f7af5c00 tmpfs  /dev/shm   
         /dev/shm  f7eabb00 f7029400 ext3   /dev/sda3          
/mnt/sda3 f7eabb80 f7209a00 binfmt_misc none               
/proc/sys/fs/binfmt_misc
f7eabd80 f7af6c00 rpc_pipefs sunrpc             /var/lib/nfs/rpc_pipefs
f7eabc00 f6de5400 autofs automount(pid2367) /net      f6e44780 c1f63000 
autofs automount(pid2357) /misc     f6e44200 f6c4d800 nfsd   nfsd       
         /proc/fs/nfsd
crash> mount -n 3287
VFSMOUNT SUPERBLK TYPE   DEVNAME            DIRNAME
f6e44180 f7eaf200 rootfs rootfs             /         f6e44700 f7ce5600 
ext3   /dev/root          /         f6e44680 f784d800 tmpfs  /dev       
         /dev      f6e44600 f7d72200 devpts /dev/devpts        /dev/pts 
  f6e44580 f7ea3c00 proc   /proc              /proc     f6e44500 
f7a7ae00 usbfs  /proc/bus/usb      /proc/bus/usb
f6e44480 f7209a00 binfmt_misc none               /proc/sys/fs/binfmt_misc
f6e44300 f7029400 ext3   /dev/sda3          /mnt/sda3 f6e44280 f7af6c00 
rpc_pipefs sunrpc             /var/lib/nfs/rpc_pipefs
f7eaba00 f6de5400 autofs automount(pid2367) /net      f7eabe00 c1f63000 
autofs automount(pid2357) /misc


----------------------------------------------------------------
Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre


-------------- next part --------------
--- crash-4.0-3.3/filesys.c	2006-09-07 21:00:08.000000000 +0200
+++ crash-4.0-3.3-patch/filesys.c	2006-09-07 22:45:24.000000000 +0200
@@ -18,7 +18,7 @@
 #include "defs.h"
 #include <linux/major.h>
 
-static void show_mounts(ulong, int);
+static void show_mounts(ulong, int, ulong);
 static int find_booted_kernel(void);
 static int find_booted_system_map(void);
 static int verify_utsname(char *);
@@ -33,7 +33,7 @@
 static int open_file_reference(struct reference *);
 static void memory_source_init(void);
 static int get_pathname_component(ulong, ulong, int, char *, char *);
-static ulong *get_mount_list(int *);
+static ulong *get_mount_list(int *, ulong);
 char *inode_type(char *, char *);
 static void match_proc_version(void);
 static void get_live_memory_source(void);
@@ -1137,6 +1137,7 @@
 {
 	int i;
 	int c, found;
+	ulong namespace_pid = (ulong)1;
 	char *spec_string;
 	char buf1[BUFSIZE];
 	char buf2[BUFSIZE];
@@ -1146,7 +1147,7 @@
 	int mh_flag = 1;
 	int save_next;
 
-        while ((c = getopt(argcnt, args, "if")) != EOF) {
+        while ((c = getopt(argcnt, args, "ifn:")) != EOF) {
                 switch(c)
 		{
 		case 'i':
@@ -1156,7 +1157,22 @@
 		case 'f':
 			flags |= MOUNT_PRINT_FILES;
 			break;
-
+		case 'n':
+			{
+				ulong context;
+				struct task_context *tc;
+				switch (str_to_context(optarg, &context, &tc)) {
+		        	case STR_PID:
+                        	case STR_TASK:
+					namespace_pid = tc->pid;
+                                	break;
+                        	case STR_INVALID:
+                                	error(FATAL, "invalid task or pid value: %s\n",
+                                        	optarg);
+                                	break;
+				}
+				break;
+			}
 		default:
 			argerrs++;
 			break;
@@ -1175,7 +1191,7 @@
                         	shift_string_left(spec_string, 2);
 
 			open_tmpfile();
-			show_mounts(0, MOUNT_PRINT_ALL);
+			show_mounts(0, MOUNT_PRINT_ALL, namespace_pid);
 
 			found = FALSE;
         		rewind(pc->tmpfile);
@@ -1201,7 +1217,7 @@
 					fp = pc->saved_fp;
 					if (flags) {
 						sscanf(buf2,"%lx",&vfsmount);
-						show_mounts(vfsmount, flags);
+						show_mounts(vfsmount, flags, namespace_pid);
 					} else {
 						if (mh_flag) {
 							fprintf(fp, mount_hdr);
@@ -1216,7 +1232,7 @@
 			close_tmpfile();
 		} while (args[++optind]);
 	} else
-		show_mounts(0, flags);
+		show_mounts(0, flags, namespace_pid);
 }
 
 /*
@@ -1224,7 +1240,7 @@
  */
 
 static void
-show_mounts(ulong one_vfsmount, int flags)
+show_mounts(ulong one_vfsmount, int flags, ulong namespace_pid)
 {
 	ulong one_vfsmount_list;
 	long sb_s_files;
@@ -1262,7 +1278,7 @@
 		mount_cnt = 1;
 		mntlist = &one_vfsmount_list;
 	} else 
-		mntlist = get_mount_list(&mount_cnt); 
+		mntlist = get_mount_list(&mount_cnt, namespace_pid); 
 
 	if (!strlen(mount_hdr)) {
 		devlen = strlen("DEVNAME");
@@ -1424,7 +1440,7 @@
  *  Allocate and fill a list of the currently-mounted vfsmount pointers.
  */
 static ulong *
-get_mount_list(int *cntptr)
+get_mount_list(int *cntptr, ulong namespace_pid)
 {
 	struct list_data list_data, *ld;
 	int mount_cnt;
@@ -1438,7 +1454,7 @@
         	get_symbol_data("vfsmntlist", sizeof(void *), &ld->start);
                	ld->end = symbol_value("vfsmntlist");
 	} else if (VALID_MEMBER(namespace_root)) {
-		if (!(tc = pid_to_context(1)))
+		if (!(tc = pid_to_context(namespace_pid)))
 	 		tc = CURRENT_CONTEXT();
 
         	readmem(tc->task + OFFSET(task_struct_namespace), KVADDR, 
@@ -1513,7 +1529,7 @@
 		goto nopath;
 
         if (VALID_MEMBER(file_f_vfsmnt)) {
-		mntlist = get_mount_list(&mount_cnt);
+		mntlist = get_mount_list(&mount_cnt, 1);
         	vfsmount_buf = GETBUF(SIZE(vfsmount));
 
         	for (m = found = 0, vfsmnt = mntlist; 


More information about the Crash-utility mailing list