<!-- 
RSS generated by JIRA (9.4.14#940014-sha1:734e6822bbf0d45eff9af51f82432957f73aa32c) at Sat Feb 10 01:30:29 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>Whamcloud Community JIRA</title>
    <link>https://jira.whamcloud.com</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.4.14</version>
        <build-number>940014</build-number>
        <build-date>05-12-2023</build-date>
    </build-info>


<item>
            <title>[LU-3044] LSeek SEEK_CUR gives incorrect value after write when file is open with O_APPEND</title>
                <link>https://jira.whamcloud.com/browse/LU-3044</link>
                <project id="10000" key="LU">Lustre</project>
                    <description>&lt;p&gt;When a file is opened with O_APPEND set, and data is written, the resulting value of the file pointer is incorrect. This is observed when using lseek with SEEK_CUR set.&lt;/p&gt;

&lt;p&gt;This does not result in corruption on subsequent writes because with O_APPEND set, the file pointer is reset to EOF before each write.  (See ULK3 on VFS)&lt;/p&gt;

&lt;p&gt;I&apos;m attaching a trivial reproducer for this problem.&lt;/p&gt;

&lt;p&gt;A bit of debugging showed me that a correct value of the file pointer is available at the same point where it is set to the incorrect value in ll_file_io_generic. &lt;/p&gt;

&lt;p&gt;Here&apos;s the sample (this is from 2.3, but the code is effectively the same in all 2.x releases) with my debug code in it to make clear exactly what I&apos;m talking about:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;ppos_out = (unsigned &lt;span class=&quot;code-object&quot;&gt;long&lt;/span&gt;) *ppos;
printk(KERN_NOTICE &lt;span class=&quot;code-quote&quot;&gt;&quot;ll_file_io_generic (before &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;) ppos: %lu\n&quot;&lt;/span&gt;,ppos_out);
&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (io-&amp;gt;ci_nob &amp;gt; 0) { 
    result = io-&amp;gt;ci_nob; 
    *ppos = io-&amp;gt;u.ci_wr.wr.crw_pos; 
    ppos_out = (unsigned &lt;span class=&quot;code-object&quot;&gt;long&lt;/span&gt;) *ppos;
    printk(KERN_NOTICE &lt;span class=&quot;code-quote&quot;&gt;&quot;ll_file_io_generic io-&amp;gt;u.ci_wr.wr.crw_pos ppos:     %lu\n&quot;&lt;/span&gt;,ppos_out); 
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The value of ppos before the *ppos = io-&amp;gt;u.ci_wr.wr.crw_pos is correct, but the value in io-&amp;gt;u.ci_wr.wr.crw_pos is not.  It is greater than expected by approximately the number of bytes in the write.  (See comment for further details.)&lt;/p&gt;

&lt;p&gt;An if statement around the assignment checking for O_APPEND corrects the issue and passes acceptance-small sanity:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;(!cl_io_is_append(io)) { 
    *ppos = io-&amp;gt;u.ci_wr.wr.crw_pos; 
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Still, I am concerned this is a band-aid and a deeper fix may be necessary.&lt;/p&gt;

&lt;p&gt;I have some more detailed information on exactly how much io-&amp;gt;u.ci_wr.wr.crw_pos; that I&apos;ll put in a subsequent comment - It&apos;s lengthy, and may not be relevant to fixing the issue.&lt;/p&gt;</description>
                <environment>SLES11SP1/SP2.  Lustre 2.x.</environment>
        <key id="18134">LU-3044</key>
            <summary>LSeek SEEK_CUR gives incorrect value after write when file is open with O_APPEND</summary>
                <type id="1" iconUrl="https://jira.whamcloud.com/secure/viewavatar?size=xsmall&amp;avatarId=11303&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.whamcloud.com/images/icons/priorities/minor.svg">Minor</priority>
                        <status id="5" iconUrl="https://jira.whamcloud.com/images/icons/statuses/resolved.png" description="A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.">Resolved</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="1">Fixed</resolution>
                                        <assignee username="emoly.liu">Emoly Liu</assignee>
                                    <reporter username="paf">Patrick Farrell</reporter>
                        <labels>
                            <label>patch</label>
                    </labels>
                <created>Wed, 27 Mar 2013 20:33:43 +0000</created>
                <updated>Sun, 3 Jun 2018 20:36:32 +0000</updated>
                            <resolved>Tue, 23 Apr 2013 13:13:31 +0000</resolved>
                                    <version>Lustre 2.3.0</version>
                                    <fixVersion>Lustre 2.4.0</fixVersion>
                    <fixVersion>Lustre 2.1.6</fixVersion>
                                        <due></due>
                            <votes>0</votes>
                                    <watches>10</watches>
                                                                            <comments>
                            <comment id="54957" author="paf" created="Wed, 27 Mar 2013 20:36:13 +0000"  >&lt;p&gt;Sorry, the original neglects to mention - This code is in lustre/llite/file.c&lt;/p&gt;</comment>
                            <comment id="54958" author="paf" created="Wed, 27 Mar 2013 20:55:27 +0000"  >&lt;p&gt;&lt;a href=&quot;http://review.whamcloud.com/#change,5861&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://review.whamcloud.com/#change,5861&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="54968" author="jay" created="Thu, 28 Mar 2013 00:23:19 +0000"  >&lt;p&gt;Let&apos;s fix it by disabling crw_pos adjustment in ll_prepare_write().&lt;/p&gt;</comment>
                            <comment id="54972" author="jay" created="Thu, 28 Mar 2013 00:27:03 +0000"  >&lt;p&gt;This piece of code is already obsoleted, we don;t need to adjust crw_pos to survive cl_page_in_io().&lt;/p&gt;

&lt;p&gt;The patch is as follows:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;index c8b0626..9a5a243 100644
--- a/lustre/llite/rw.c
+++ b/lustre/llite/rw.c
@@ -237,17 +237,6 @@ &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt; ll_prepare_write(struct file *file, struct page *vmpage, unsigned from,
                 struct cl_page *page = lcc-&amp;gt;lcc_page;
 
                 cl_page_assume(env, io, page);
-                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (cl_io_is_append(io)) {
-                        struct cl_object   *obj   = io-&amp;gt;ci_obj;
-                        struct inode       *inode = ccc_object_inode(obj);
-                        /**
-                         * In VFS file-&amp;gt;page write loop, &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; appending, the
-                         * write offset might be reset according to the &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt;
-                         * file size before holding i_mutex. So crw_pos should
-                         * be reset here. BUG:17711.
-                         */
-                        io-&amp;gt;u.ci_wr.wr.crw_pos = i_size_read(inode);
-                }
                 result = cl_io_prepare_write(env, io, page, from, to);
                 &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (result == 0) {
                         /*
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Patrick, can you please productize it? Thanks in advance.&lt;/p&gt;</comment>
                            <comment id="55024" author="pjones" created="Thu, 28 Mar 2013 17:46:39 +0000"  >&lt;p&gt;Emoly&lt;/p&gt;

&lt;p&gt;Could you please look into this one?&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

&lt;p&gt;Peter&lt;/p&gt;</comment>
                            <comment id="55087" author="paf" created="Fri, 29 Mar 2013 14:16:47 +0000"  >&lt;p&gt;Jinshan,&lt;/p&gt;

&lt;p&gt;Sure.  I&apos;ll build and test locally before pushing it upstream.&lt;/p&gt;

&lt;p&gt;To be clear I understand, you&apos;re saying this comment and the line of code associated with it are obsolete now:&lt;br/&gt;
&amp;#8212;&lt;br/&gt;
/**&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;* In VFS file-&amp;gt;page write loop, for appending, the&lt;/li&gt;
	&lt;li&gt;* write offset might be reset according to the new&lt;/li&gt;
	&lt;li&gt;* file size before holding i_mutex. So crw_pos should&lt;/li&gt;
	&lt;li&gt;* be reset here. BUG:17711.&lt;/li&gt;
	&lt;li&gt;*/&lt;/li&gt;
	&lt;li&gt;io-&amp;gt;u.ci_wr.wr.crw_pos = i_size_read(inode);&lt;br/&gt;
&amp;#8212;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Could you explain why?  I&apos;d both just like to know and need it for the mod header.&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;Edit&amp;#93;&lt;/span&gt;&lt;br/&gt;
One more thing - When you explain why, could you clarify if this applies to all 2.x versions, or if not, to which ones it does apply?&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;/Edit&amp;#93;&lt;/span&gt;&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Patrick&lt;/li&gt;
&lt;/ul&gt;
</comment>
                            <comment id="55107" author="paf" created="Fri, 29 Mar 2013 18:00:07 +0000"  >&lt;p&gt;Jinshan,&lt;/p&gt;

&lt;p&gt;I tested your change locally and it appears OK.  I&apos;ve pushed a patch to Gerrit for testing.&lt;br/&gt;
The only issue is the commmit message.  I need more details from you to write that correctly.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;</comment>
                            <comment id="55110" author="jay" created="Fri, 29 Mar 2013 18:12:25 +0000"  >&lt;p&gt;We used to adjust crw_pos in ll_prepare_write() to survive the sanity check of LASSERT(cl_page_in_io(page, io)) in cl_io_prepare_write(). However, crw_pos is changed again cl_io_rw_advance() therefore append write has the issue of setting ppos wrong.&lt;/p&gt;

&lt;p&gt;The adjustment is not needed anymore as we have changed cl_page_in_io() to exclude append write case.&lt;/p&gt;</comment>
                            <comment id="55118" author="paf" created="Fri, 29 Mar 2013 19:01:17 +0000"  >&lt;p&gt;Jinshan,&lt;/p&gt;

&lt;p&gt;Thank you, I follow now.  I&apos;ve pushed a patch set with an updated commit message with your information.&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Patrick&lt;/li&gt;
&lt;/ul&gt;
</comment>
                            <comment id="55627" author="paf" created="Fri, 5 Apr 2013 17:46:00 +0000"  >&lt;p&gt;Jinshan,&lt;/p&gt;

&lt;p&gt;I am still waiting for review on the mod.  Is there anyone else you would suggest to have review it?&lt;/p&gt;

&lt;p&gt;Thanks,!&lt;/p&gt;</comment>
                            <comment id="56800" author="pjones" created="Tue, 23 Apr 2013 13:13:31 +0000"  >&lt;p&gt;Landed for 2.4&lt;/p&gt;</comment>
                            <comment id="60250" author="green" created="Mon, 10 Jun 2013 15:22:39 +0000"  >&lt;p&gt;This is also oalnded into b2_1 for 2.1.6&lt;/p&gt;</comment>
                            <comment id="61335" author="mabraham" created="Tue, 25 Jun 2013 23:10:05 +0000"  >&lt;p&gt;For the record, as reported in &lt;a href=&quot;https://jira.whamcloud.com/browse/LU-3440&quot; title=&quot;ftello() system call not grok&amp;#39;ing with expected file position location&quot; class=&quot;issue-link&quot; data-issue-key=&quot;LU-3440&quot;&gt;&lt;del&gt;LU-3440&lt;/del&gt;&lt;/a&gt;, this bug can produce problems, including corruption.&lt;/p&gt;

&lt;p&gt;If an ftell returns the incorrect file pointer, and the client assumes it is EOF like it should be, further processing based on (for example) a computed current file size will be wrong.&lt;/p&gt;

&lt;p&gt;But I&apos;m glad to see it is fixed &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.whamcloud.com/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="52453">LU-11069</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="19292">LU-3440</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="12435" name="lseek_simple.c" size="640" author="paf" created="Wed, 27 Mar 2013 20:33:43 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                            <customfield id="customfield_10890" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10390" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hzvmhz:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10090" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>7438</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10060" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Severity</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10022"><![CDATA[3]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                        </customfields>
    </item>
</channel>
</rss>