From patchwork Mon Sep 28 17:34:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Garlick X-Patchwork-Id: 50426 X-Patchwork-Delegate: ericvh@gmail.com 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 n8SHYaPH016756 for ; Mon, 28 Sep 2009 17:34:36 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 1MsK77-00035h-AC; Mon, 28 Sep 2009 17:34:17 +0000 Received: from sfi-mx-2.v28.ch3.sourceforge.com ([172.29.28.122] helo=mx.sourceforge.net) by 3yr0jf1.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1MsK76-00035Z-EQ for v9fs-developer@lists.sourceforge.net; Mon, 28 Sep 2009 17:34:16 +0000 Received-SPF: pass (72vjzd1.ch3.sourceforge.com: domain of llnl.gov designates 128.115.41.82 as permitted sender) client-ip=128.115.41.82; envelope-from=garlick@llnl.gov; helo=nspiron-2.llnl.gov; Received: from nspiron-2.llnl.gov ([128.115.41.82]) by 72vjzd1.ch3.sourceforge.com with esmtp (Exim 4.69) id 1MsK70-00008t-LU for v9fs-developer@lists.sourceforge.net; Mon, 28 Sep 2009 17:34:16 +0000 X-Attachments: None Received: from eris.llnl.gov ([134.9.2.84]) by nspiron-2.llnl.gov with ESMTP; 28 Sep 2009 10:34:03 -0700 Received: from localhost (mrhankey [192.168.1.135]) by eris.llnl.gov (Postfix) with ESMTP id D13F87C4A5; Mon, 28 Sep 2009 10:34:03 -0700 (PDT) Date: Mon, 28 Sep 2009 10:34:02 -0700 From: Jim Garlick To: Latchesar Ionkov Message-ID: <20090928173402.GA5731@llnl.gov> References: Mime-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.2i X-Spam-Score: -1.4 (-) 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.1 AWL AWL: From: address is in the auto white-list X-Headers-End: 1MsK70-00008t-LU Cc: 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 The patch below also addresses a couple of other corner cases in readdir seen with a large (e.g. 64k) msize. I'm not sure what people think of my co-opting of fid->aux here. I'd be happy to rework if there's a better way. Jim When the size of the user supplied buffer passed to readdir is smaller than the data returned in one go by the 9P read request, v9fs_dir_readdir() currently discards extra data so that, on the next call, a 9P read request will be issued with offset < previous offset + bytes returned, which voilates the constraint described in paragraph 3 of read(5) description. This patch preseves the leftover data in fid->aux for use in the next call. Also, if multiple 9P read requests are required to satisfy the user's request, clear the 'i' index so that dirents returned in subsequent responses are not dropped, Finally, don't increment flip->f_pos if filldir fails. ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf Index: v9fs/vfs_dir.c =================================================================== --- v9fs/vfs_dir.c (.../tags/v9fs-2009.08.27.9psac-3chaos) (revision 8998) +++ v9fs/vfs_dir.c (.../branches/9p-sac) (revision 8998) @@ -74,7 +74,7 @@ struct p9_fid *fid; int buflen; char *statbuf; - int n, i = 0; + int n, i, reclen; P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->COMPAT_f_dentry->d_name.name); fid = filp->private_data; @@ -85,12 +85,20 @@ return -ENOMEM; while (1) { - err = v9fs_file_readn(filp, statbuf, NULL, buflen, - fid->rdir_fpos); - if (err <= 0) - break; - - n = err; + if (fid->rdir_fpos > filp->f_pos) { + n = fid->rdir_fpos - filp->f_pos; + memcpy(statbuf, fid->aux, n); + kfree(fid->aux); + fid->aux = NULL; + } else { + err = v9fs_file_readn(filp, statbuf, NULL, buflen, + fid->rdir_fpos); + if (err <= 0) + break; + n = err; + fid->rdir_fpos += n; + } + i = 0; while (i < n) { err = p9stat_read(statbuf + i, buflen-i, &st, fid->clnt->dotu); @@ -100,21 +108,25 @@ p9stat_free(&st); goto free_and_exit; } + reclen = st.size+2; - i += st.size+2; - fid->rdir_fpos += 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) { + 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; } } Index: 9p/client.c =================================================================== --- 9p/client.c (.../tags/v9fs-2009.08.27.9psac-3chaos) (revision 8995) +++ 9p/client.c (.../branches/9p-sac) (revision 8995) @@ -615,6 +615,8 @@ spin_lock_irqsave(&clnt->lock, flags); list_del(&fid->flist); spin_unlock_irqrestore(&clnt->lock, flags); + if (fid->aux) + kfree(fid->aux); kfree(fid); }