linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "sudharsan  vijayaraghavan" <my_goal@rediffmail.com>
To: linux-kernel@vger.kernel.org
Cc: svijayar@cisco.com, narendiran_srinivasan@satyam.com
Subject: fd_install question ??
Date: 6 Mar 2003 22:46:08 -0000	[thread overview]
Message-ID: <20030306224608.29991.qmail@webmail17.rediffmail.com> (raw)

Hi,

We modified the existing /usr/src/linux/fs/pipe.c such that we 
need more than 2 file descriptors where one of the descriptors 
will be writer and others should be readers.

However while doing an fd_install on the third descriptor we 
encounter an "OOPS" .

The peculair thing is we are able to successfully read using the 
third descriptor , while our program exits we encounter the 
"OOPS".

We modified the code as follows :

I have highlighted modifications using arrows ( --> ):
------------------------------------------------------

We made fd[0] as write end and fd[1],fd[2] as read ends.
We also successfully received three file descriptors namely 3,4,5 
 from each of the three get_unused_fd() calls respectively.

As specified earlier we were able to successfully read using the 
third file descriptor.

Please spare time to go through the modifications we made in the 
code and help us to sort out this issue.

Thanks in advance,
Sudharsan.

++++++++++++++++++++++++++++++++++++++++++++++++++++++

     int do_pipe(int *fd)
  {
          struct qstr this;

          char name[32];

          struct dentry *dentry;

          struct inode * inode;

          //struct file *f1, *f2;
-->        struct file *f1, *f2, *f3;

          int error;

          //int i,j;
-->        int i,j,k;

          error = -ENFILE;

          f1 = get_empty_filp();
          if (!f1)
                  goto no_files;

          f2 = get_empty_filp();
          if (!f2)
                  goto close_f1;

-->      if (!f3)
-->             goto close_f12

          inode = get_pipe_inode();

          if (!inode)
         //         goto close_f12;
-->                goto close_f123

          error = get_unused_fd();

          if (error < 0)
                  goto close_f12_inode;
          i = error;

          error = get_unused_fd();
          if (error < 0)
                  goto close_f12_inode_i;
          j = error;

-->      error = get_unused_fd();
-->      if (error < 0)
-->              goto close_f12_inode_i_j;
-->      k=error;

         error = -ENOMEM;

          sprintf(name, "[%lu]", inode->i_ino);
          this.name = name;
          this.len = strlen(name);
          this.hash = inode->i_ino; /* will go */

          dentry = d_alloc(pipe_mnt->mnt_sb->s_root, &this);

          if (!dentry)
          //        goto close_f12_inode_i_j;
-->                goto close_f12_inode_i_j_k;

          dentry->d_op = &pipefs_dentry_operations;

          d_add(dentry, inode);

         // f1->f_vfsmnt = f2->f_vfsmnt = 
mntget(mntget(pipe_mnt));
-->        f1->f_vfsmnt = f2->f_vfsmnt = f3->f_vfsmnt = 
mntget(mntget(pipe_mnt));
         // f1->f_dentry = f2->f_dentry = dget(dentry);
-->        f1->f_dentry = f2->f_dentry = f3->f_dentry = 
dget(dentry);
          /* read file */

          f1->f_pos = f2->f_pos = 0;
         // f1->f_flags = O_RDONLY;
-->        f1->f_flags = O_WRONLY;
          //f1->f_op = &read_pipe_fops;
-->        f1->f_op = &write_pipe_fops;
            f1->f_mode = 1;
            f1->f_version = 0;

          /* write file */
         // f2->f_flags = O_WRONLY;
-->        f2->f_flags = O_RDONLY;
         // f2->f_op = &write_pipe_fops;
-->        f2->f_op = &read_pipe_fops;
            f2->f_mode = 2;
            f2->f_version = 0;

-->        f3->f_flags = O_RDONLY;
-->        f3->f_op = &read_pipe_fops;
            f3->f_mode = 2;
            f3->f_version = 0;

          fd_install(i, f1);
          fd_install(j, f2);
-->      fd_install(k, f3);

          fd[0] = i;
          fd[1] = j;
-->      fd[2] = k;

          return 0;

-->  close_f12_inode_i_j_k :
-->       put_unused_fd(k);

      close_f12_inode_i_j:
          put_unused_fd(j);

      close_f12_inode_i:
          put_unused_fd(i);

      close_f12_inode:
          free_page((unsigned long) PIPE_BASE(*inode));
          kfree(inode->i_pipe);
          inode->i_pipe = NULL;
          iput(inode);

-->   close_f123:
-->         put_filp(f3);

  close_f12:
          put_filp(f2);

  close_f1:
          put_filp(f1);

  no_files:
          return error;
  }

++++++++++++++++++++++++++++++++++++++++++++++++


             reply	other threads:[~2003-03-06 22:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-06 22:46 sudharsan  vijayaraghavan [this message]
2003-03-06 23:06 ` fd_install question ?? Mikael Pettersson
2003-03-06 23:28 ` Chris Wright

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030306224608.29991.qmail@webmail17.rediffmail.com \
    --to=my_goal@rediffmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=narendiran_srinivasan@satyam.com \
    --cc=svijayar@cisco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).