From patchwork Tue Oct 27 20:13:29 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Van Hensbergen X-Patchwork-Id: 56170 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9RKEZRI008605 for ; Tue, 27 Oct 2009 20:14:35 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by 3yr0jf1.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1N2sQJ-0005oQ-Sh; Tue, 27 Oct 2009 20:13:43 +0000 Received: from sfi-mx-4.v28.ch3.sourceforge.com ([172.29.28.124] helo=mx.sourceforge.net) by 3yr0jf1.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1N2sQJ-0005oF-La for v9fs-developer@lists.sourceforge.net; Tue, 27 Oct 2009 20:13:43 +0000 Received-SPF: pass (1b2kzd1.ch3.sourceforge.com: domain of gmail.com designates 209.85.219.206 as permitted sender) client-ip=209.85.219.206; envelope-from=ericvh@gmail.com; helo=mail-ew0-f206.google.com; Received: from mail-ew0-f206.google.com ([209.85.219.206]) by 1b2kzd1.ch3.sourceforge.com with esmtp (Exim 4.69) id 1N2sQC-0003XX-2Z for v9fs-developer@lists.sourceforge.net; Tue, 27 Oct 2009 20:13:43 +0000 Received: by ewy2 with SMTP id 2so95449ewy.10 for ; Tue, 27 Oct 2009 13:13:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.86.83 with SMTP id v61mr249213wee.80.1256674409817; Tue, 27 Oct 2009 13:13:29 -0700 (PDT) In-Reply-To: <20090928173402.GA5731@llnl.gov> References: <20090928173402.GA5731@llnl.gov> Date: Tue, 27 Oct 2009 15:13:29 -0500 Message-ID: From: Eric Van Hensbergen To: Jim Garlick X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 DKIM_VERIFIED Domain Keys Identified Mail: signature passes verification 0.0 DKIM_SIGNED Domain Keys Identified Mail: message has a signature X-Headers-End: 1N2sQC-0003XX-2Z Cc: Latchesar Ionkov , V9FS Developers , rminnich@dancer.ca.sandia.gov Subject: Re: [V9fs-developer] Small patch X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: v9fs-developer-bounces@lists.sourceforge.net diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index cae53d4..735bb60 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -75,6 +75,7 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, int buflen; char *statbuf; int n, i = 0; + int reclen = 0; P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name fid = filp->private_data; @@ -85,13 +86,35 @@ static int v9fs_dir_readdir(struct file *filp, void *diren return -ENOMEM; while (1) { - err = v9fs_file_readn(filp, statbuf, NULL, buflen, + if (fid->rdir_fpos > filp->f_pos) { + n = fid->rdir_fpos - filp->f_pos; + if (n > buflen) { + printk(KERN_ERR + "9p: readdir: n=%d buflen=%d\n", + n, buflen); + err = -EIO; + goto free_and_exit; + } + if (!fid->aux) { + printk(KERN_ERR + "9p: readdir: null aux rd=%d fp=%d\n", + fid->rdir_fpos, filp->f_pos); + err = -EIO; + goto free_and_exit; + } + memcpy(statbuf, fid->aux, n); + /* TODO: would it make more sense to leave buffer? */ + kfree(fid->aux); + fid->aux = NULL; + } else { + err = v9fs_file_readn(filp, statbuf, NULL, buflen, fid->rdir_fpos - if (err <= 0) - break; - + if (err <= 0) + break; + n = err; + fid->rdir_fpos += n; + } i = 0; - n = err; while (i < n) { err = p9stat_read(statbuf + i, buflen-i, &st, fid->clnt->dotu); @@ -101,21 +124,32 @@ static int v9fs_dir_readdir(struct file *filp, void *dir p9stat_free(&st); goto free_and_exit; } - - i += st.size+2; - fid->rdir_fpos += st.size+2; + reclen = st.size+2; over = filldir(dirent, st.name, strlen(st.name), filp->f_pos, v9fs_qid2ino(&st.qid), dt_type(&st)); - filp->f_pos += st.size+2; - p9stat_free(&st); if (over) { + /* TODO: alloc msize buffer instead? */ + if (fid->aux) { + printk(KERN_ERR "9p: readdir: aux\n"); + err = -EIO; + goto free_and_exit; + } + fid->aux = kmalloc(n - i, GFP_KERNEL); + if (!fid->aux) { + err = -ENOMEM; + goto free_and_exit; + } + memcpy(fid->aux, statbuf + i, n - i); + err = 0; goto free_and_exit; } + filp->f_pos += reclen; + i += reclen; } } diff --git a/net/9p/client.c b/net/9p/client.c index 5bf5f22..31f01e3 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -609,6 +609,8 @@ static void p9_fid_destroy(struct p9_fid *fid) spin_lock_irqsave(&clnt->lock, flags); list_del(&fid->flist); spin_unlock_irqrestore(&clnt->lock, flags); + if (fid->aux) + kfree(fid->aux); kfree(fid); }