[LU-9936] ldiskfs_write_ldd() calls fsync(filep->_fileno) but doesn't fflush() flip first Created: 01/Sep/17  Updated: 29/Jan/22

Status: Open
Project: Lustre
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: John Hammond Assignee: WC Triage
Resolution: Unresolved Votes: 0
Labels: easy, mount

Severity: 3
Rank (Obsolete): 9223372036854775807

 Description   

In ldiskfs_write_ldd():

 270         num = fwrite(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
 271         if (num < 1 && ferror(filep)) {
 272                 fprintf(stderr, "%s: Unable to write to file (%s): %s\n",
 273                         progname, filepnm, strerror(errno));
 274                 fclose(filep);
 275                 goto out_umnt;
 276         }
 277         fsync(filep->_fileno);
 278         fclose(filep);
 

Calling fsync() without first calling fflush() is ineffective since there will likely still be unwritten data in the userspace buffer.

Also we should use fileno(filp) instead of accessing filp->_fileno.

We should check the returns of fflush(), fsync(), and fclose() for failure. Since an error is more likely to be reported there than from fwrite().



 Comments   
Comment by John Hammond [ 05/Sep/17 ]

Andreas has pointed out that there is no reason to use stdio here.

Comment by Andreas Dilger [ 05/Sep/17 ]

There doesn't appear to be a good reason for using buffered stream IO here. Instead, this should use Unix IO (open(), write(), fsync(), and close()).

Generated at Sat Feb 10 02:30:37 UTC 2024 using Jira 9.4.14#940014-sha1:734e6822bbf0d45eff9af51f82432957f73aa32c.