Dave Anderson wrote:
Rachita Kothiyal wrote:
On Fri, Dec 23, 2005 at 05:03:30PM -0500, anderson@prospeed.net wrote:
>
> Hi Rachita,
>
> This looks good -- the only thing I'll change is to print out the
> offsets unconditionally in dump_offset_table() -- I actually
> want to see everything in the table, including the -1's for
> the invalid members.

Hi Dave

I am resending the patch with changes as suggested.
Please review.

Thanks
Rachita
 

Strange -- I thought this patch was a no-brainer, but there seems to be
a bizarre problem with this patch, one that I've not gotten a handle on
yet, nor have I ever seen such behaviour before.  I'm testing the "files"
command on RHEL3 and RHEL4, and both see the same behaviour.

If I run "foreach files" in the foreground, I get the expected output.
But if I run "foreach files > output", all tasks show "no open files".
So for some reason the change of the output stream is affecting the
operation of the command?

And probably related, check this out, where the first "files 2365"
command takes syslogd's PID and works OK -- but if I set the crash
context to that PID, and then do just a "files" alone I get the
"no open files" response:

crash> files 2365
PID: 2365   TASK: 2184e7b0  CPU: 1   COMMAND: "syslogd"
ROOT: /    CWD: /
 FD    FILE     DENTRY    INODE    TYPE  PATH
  0  21280880  202a963c  1d086aac  SOCK  socket:/[5686]
  1  20e7a080  1fcd63dc  1a0b5548  REG   /var/log/messages
  2  20852180  1fcc4df4  1a0b5320  REG   /var/log/secure
  3  20852980  202a9c2c  1a0b50f8  REG   /var/log/maillog
  4  20dd7280  202a9cc4  1a768de8  REG   /var/log/cron
  5  21383280  202a9d5c  1a768bc0  REG   /var/log/spooler
  6  20852880  202a9f24  1a768998  REG   /var/log/boot.log
  7  216e6380  202a950c  1a768548  REG   /var/log/news/news.crit
  8  2109aa80  202a9df4  1a768320  REG   /var/log/news/news.err
  9  216d7680  202a9214  1a7680f8  REG   /var/log/news/news.notice

crash> set 2365
    PID: 2365
COMMAND: "syslogd"
   TASK: 2184e7b0  [THREAD_INFO: 20cd9000]
    CPU: 1
  STATE: TASK_INTERRUPTIBLE
crash> files
PID: 2365   TASK: 2184e7b0  CPU: 1   COMMAND: "syslogd"
ROOT: /    CWD: /
No open files
crash>

Can you try the same thing on your 2.6.14 kernel?

Thanks,
  Dave
 
 

Hi Rachita,

This patch-to-your-patch seems to fix it:

RCS file: /nfs/projects/cvs/crash/filesys.c,v
retrieving revision 1.45
diff -r1.45 filesys.c
2015c2015,2016
<       ulong files_struct_addr, fdtable_addr;
---
>       ulong files_struct_addr;
>       ulong fdtable_addr = 0;
2153c2154,2155
<       if (!fdtable_addr || !files_struct_addr || max_fdset == 0 || max_fds == 0) {
---
>       if ((VALID_MEMBER(files_struct_fdt) && !fdtable_addr) ||
>           !files_struct_addr || max_fdset == 0 || max_fds == 0) {

With fdtable_addr uninitialized, it only gets past the "if" statement
above on a pre-2.6.14 kernel if there were non-zero garbage left there
on the stack.  If there happened to be a zero there, the "if" path is
taken inadvertently, and it just prints "No open files".

But do you agree with my logic of the enclosed checking of the validity first
and then the fdtable_addr?  Seems right.

Dave
 

 
 
 
 o Following changes in the 'files_struct' structure from
   kernels 2.6.14 onwards, this patch attempts to fix the
   broken files command.

Signed-off-by: Rachita Kothiyal <rachita@in.ibm.com>
---

 defs.h    |    6 ++++
 filesys.c |   82 ++++++++++++++++++++++++++++++++++++++++++++++----------------
 symbols.c |   11 ++++++++
 3 files changed, 78 insertions(+), 21 deletions(-)

diff -puN filesys.c~crash-fix-files-command filesys.c
--- crash-4.0-2.17/filesys.c~crash-fix-files-command    2005-12-23 18:26:05.000000000 +0530
+++ crash-4.0-2.17-rachita/filesys.c    2005-12-23 18:26:16.000000000 +0530
@@ -1710,12 +1710,20 @@ vfs_init(void)
        MEMBER_OFFSET_INIT(fs_struct_pwd, "fs_struct", "pwd");
        MEMBER_OFFSET_INIT(fs_struct_rootmnt, "fs_struct", "rootmnt");
        MEMBER_OFFSET_INIT(fs_struct_pwdmnt, "fs_struct", "pwdmnt");
-       MEMBER_OFFSET_INIT(files_struct_max_fds, "files_struct", "max_fds");
-       MEMBER_OFFSET_INIT(files_struct_max_fdset, "files_struct", "max_fdset");
-       MEMBER_OFFSET_INIT(files_struct_open_fds, "files_struct", "open_fds");
        MEMBER_OFFSET_INIT(files_struct_open_fds_init,
                "files_struct", "open_fds_init");
-       MEMBER_OFFSET_INIT(files_struct_fd, "files_struct", "fd");
+       MEMBER_OFFSET_INIT(files_struct_fdt, "files_struct", "fdt");
+       if ( VALID_MEMBER(files_struct_fdt)) {
+               MEMBER_OFFSET_INIT(fdtable_max_fds, "fdtable", "max_fds");
+               MEMBER_OFFSET_INIT(fdtable_max_fdset, "fdtable", "max_fdset");
+               MEMBER_OFFSET_INIT(fdtable_open_fds, "fdtable", "open_fds");
+               MEMBER_OFFSET_INIT(fdtable_fd, "fdtable", "fd");
+       } else {
+               MEMBER_OFFSET_INIT(files_struct_max_fds, "files_struct", "max_fds");
+               MEMBER_OFFSET_INIT(files_struct_max_fdset, "files_struct", "max_fdset");
+               MEMBER_OFFSET_INIT(files_struct_open_fds, "files_struct", "open_fds");
+               MEMBER_OFFSET_INIT(files_struct_fd, "files_struct", "fd");
+       }
        MEMBER_OFFSET_INIT(file_f_dentry, "file", "f_dentry");
        MEMBER_OFFSET_INIT(file_f_vfsmnt, "file", "f_vfsmnt");
        MEMBER_OFFSET_INIT(file_f_count, "file", "f_count");
@@ -1766,6 +1774,8 @@ vfs_init(void)
        STRUCT_SIZE_INIT(umode_t, "umode_t");
        STRUCT_SIZE_INIT(dentry, "dentry");
        STRUCT_SIZE_INIT(files_struct, "files_struct");
+       if (VALID_MEMBER(files_struct_fdt))
+               STRUCT_SIZE_INIT(fdtable, "fdtable");
        STRUCT_SIZE_INIT(file, "file");
        STRUCT_SIZE_INIT(inode, "inode");
        STRUCT_SIZE_INIT(vfsmount, "vfsmount");
@@ -2002,8 +2012,8 @@ void
 open_files_dump(ulong task, int flags, struct reference *ref)
 {
         struct task_context *tc;
-       ulong files_struct_addr;
-       char *files_struct_buf;
+       ulong files_struct_addr, fdtable_addr;
+       char *files_struct_buf, *fdtable_buf = NULL;
        ulong fs_struct_addr;
        char *dentry_buf, *fs_struct_buf;
        ulong root_dentry, pwd_dentry;
@@ -2031,6 +2041,8 @@ open_files_dump(ulong task, int flags, s
        BZERO(root_pathname, BUFSIZE);
        BZERO(pwd_pathname, BUFSIZE);
        files_struct_buf = GETBUF(SIZE(files_struct));
+       if (VALID_SIZE(fdtable))
+               fdtable_buf = GETBUF(SIZE(fdtable));
        fill_task_struct(task);

        sprintf(files_header, " FD%s%s%s%s%s%s%sTYPE%sPATH\n",
@@ -2111,24 +2123,41 @@ open_files_dump(ulong task, int flags, s

        files_struct_addr = ULONG(tt->task_struct + OFFSET(task_struct_files));

-        if (files_struct_addr) {
-                readmem(files_struct_addr, KVADDR, files_struct_buf,
-                       SIZE(files_struct), "files_struct buffer",
-                       FAULT_ON_ERROR);
-
-               max_fdset = INT(files_struct_buf +
+       if (files_struct_addr) {
+               readmem(files_struct_addr, KVADDR, files_struct_buf,
+                       SIZE(files_struct), "files_struct buffer",
+                       FAULT_ON_ERROR);
+
+               if (VALID_MEMBER(files_struct_max_fdset)) {
+                       max_fdset = INT(files_struct_buf +
                        OFFSET(files_struct_max_fdset));

-               max_fds = INT(files_struct_buf +
-                        OFFSET(files_struct_max_fds));
-        }
+                       max_fds = INT(files_struct_buf +
+                       OFFSET(files_struct_max_fds));
+               }
+       }
+
+       if (VALID_MEMBER(files_struct_fdt)) {
+               fdtable_addr = ULONG(files_struct_buf + OFFSET(files_struct_fdt));

-       if (!files_struct_addr || max_fdset == 0 || max_fds == 0) {
+               if (fdtable_addr) {
+                       readmem(fdtable_addr, KVADDR, fdtable_buf,                                                              SIZE(fdtable), "fdtable buffer",                                                                 FAULT_ON_ERROR);
+
+                       max_fdset = INT(fdtable_buf +
+                               OFFSET(fdtable_max_fdset));
+                       max_fds = INT(fdtable_buf +
+                               OFFSET(fdtable_max_fds));
+               }
+       }
+
+       if (!fdtable_addr || !files_struct_addr || max_fdset == 0 || max_fds == 0) {
                if (ref) {
                        if (ref->cmdflags & FILES_REF_FOUND)
                                fprintf(fp, "\n");
                } else
                        fprintf(fp, "No open files\n");
+               if (fdtable_buf)
+                       FREEBUF(fdtable_buf);
                FREEBUF(files_struct_buf);
                return;
        }
@@ -2150,8 +2179,12 @@ open_files_dump(ulong task, int flags, s
                }
         }

-       open_fds_addr = ULONG(files_struct_buf +
-               OFFSET(files_struct_open_fds));
+       if (VALID_MEMBER(fdtable_open_fds))
+               open_fds_addr = ULONG(fdtable_buf +
+                       OFFSET(fdtable_open_fds));
+       else
+               open_fds_addr = ULONG(files_struct_buf +
+                       OFFSET(files_struct_open_fds));

        if (open_fds_addr) {
                if (VALID_MEMBER(files_struct_open_fds_init) &&
@@ -2161,16 +2194,21 @@ open_files_dump(ulong task, int flags, s
                                OFFSET(files_struct_open_fds_init),
                                &open_fds, sizeof(fd_set));
                else
-                       readmem(open_fds_addr, KVADDR, &open_fds,
-                               sizeof(fd_set), "files_struct open_fds",
+                       readmem(open_fds_addr, KVADDR, &open_fds,
+                               sizeof(fd_set), "fdtable open_fds",
                                FAULT_ON_ERROR);
        }

-       fd = ULONG(files_struct_buf + OFFSET(files_struct_fd));
+       if (VALID_MEMBER(fdtable_fd))
+               fd = ULONG(fdtable_buf + OFFSET(fdtable_fd));
+       else
+               fd = ULONG(files_struct_buf + OFFSET(files_struct_fd));

        if (!open_fds_addr || !fd) {
                 if (ref && (ref->cmdflags & FILES_REF_FOUND))
                        fprintf(fp, "\n");
+               if (fdtable_buf)
+                       FREEBUF(fdtable_buf);
                FREEBUF(files_struct_buf);
                return;
        }
@@ -2224,6 +2262,8 @@ open_files_dump(ulong task, int flags, s
        if (ref && (ref->cmdflags & FILES_REF_FOUND))
                fprintf(fp, "\n");

+       if (fdtable_buf)
+               FREEBUF(fdtable_buf);
        FREEBUF(files_struct_buf);
 }

diff -puN defs.h~crash-fix-files-command defs.h
--- crash-4.0-2.17/defs.h~crash-fix-files-command       2005-12-23 18:26:24.000000000 +0530
+++ crash-4.0-2.17-rachita/defs.h       2005-12-23 18:26:33.000000000 +0530
@@ -980,6 +980,11 @@ struct offset_table {
        long hw_interrupt_type_set_affinity;
        long irq_cpustat_t___softirq_active;
        long irq_cpustat_t___softirq_mask;
+       long fdtable_max_fds;
+       long fdtable_max_fdset;
+       long fdtable_open_fds;
+       long fdtable_fd;
+       long files_struct_fdt;
         long files_struct_max_fds;
         long files_struct_max_fdset;
         long files_struct_open_fds;
@@ -1253,6 +1258,7 @@ struct size_table {         /* stash of
        long umode_t;
        long dentry;
        long files_struct;
+       long fdtable;
        long fs_struct;
        long file;
        long inode;
diff -puN symbols.c~crash-fix-files-command symbols.c
--- crash-4.0-2.17/symbols.c~crash-fix-files-command    2005-12-23 18:27:16.000000000 +0530
+++ crash-4.0-2.17-rachita/symbols.c    2006-01-03 12:07:09.579170576 +0530
@@ -5976,6 +5976,16 @@ dump_offset_table(char *spec, ulong make
        fprintf(fp, "  irq_cpustat_t___softirq_mask: %ld\n",
                OFFSET(irq_cpustat_t___softirq_mask));

+        fprintf(fp, "              files_struct_fdt: %ld\n",
+               OFFSET(files_struct_fdt));
+        fprintf(fp, "               fdtable_max_fds: %ld\n",
+               OFFSET(fdtable_max_fds));
+        fprintf(fp, "             fdtable_max_fdset: %ld\n",
+               OFFSET(fdtable_max_fdset));
+        fprintf(fp, "              fdtable_open_fds: %ld\n",
+               OFFSET(fdtable_open_fds));
+        fprintf(fp, "                    fdtable_fd: %ld\n",
+               OFFSET(fdtable_fd));
         fprintf(fp, "          files_struct_max_fds: %ld\n",
                OFFSET(files_struct_max_fds));
         fprintf(fp, "        files_struct_max_fdset: %ld\n",
@@ -6525,6 +6535,7 @@ dump_offset_table(char *spec, ulong make
        fprintf(fp, "                     fs_struct: %ld\n", SIZE(fs_struct));
        fprintf(fp, "                  files_struct: %ld\n",
                SIZE(files_struct));
+       fprintf(fp, "                       fdtable: %ld\n", SIZE(fdtable));
        fprintf(fp, "                          file: %ld\n", SIZE(file));
        fprintf(fp, "                         inode: %ld\n", SIZE(inode));
        fprintf(fp, "                      vfsmount: %ld\n", SIZE(vfsmount));
_

--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility


-- Crash-utility mailing list Crash-utility@redhat.com https://www.redhat.com/mailman/listinfo/crash-utility