Re: fs synchronisation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Pradeep Singh wrote:

> there is a field like  sync_fs( struct super_block *sb, int wait ) and void 
> write_inode( struct inode *inode, int wait ) .
> 
> i got wat it meant but the wait parameter is used to specify whether the 
> operation should b synchronous or not.

Right.

> how does it ensures synchronisation and with whom ?? ?

If "wait" is TRUE, then the function will not return until the
synchronisation (of the filesystem in the case of sync_fs and of the
inode in the case of write_inode) has been done. On the contrary, if you
call these functions with "wait" equal to FALSE, then it means that you
request a synchronisation, but the function will return before the data
will be really written to the disk.

Have a look at http://lxr.linux.no/source/fs/ext2/inode.c#L1224, which
is in the implementation of the ext2 write inode:

1224         mark_buffer_dirty(bh);
1225         if (do_sync) {
1226                 sync_dirty_buffer(bh);
1227                 if (buffer_req(bh) && !buffer_uptodate(bh)) {
1228                         printk ("IO error syncing ext2 inode
[%s:%08lx]\n",
1229                                 sb->s_id, (unsigned long) ino);
1230                         err = -EIO;
1231                 }
1232         }

(do_sync is the "wait" parameter we discussed above). If you look at the
code of sync_dirty_buffer(), it's in fact doing a wait_on_buffer(),
which will wait for the completion of the operation.

> my ques is when and how does sys_read() and sys_write() pass control to the VFS.???

Right there: http://lxr.linux.no/source/fs/read_write.c#L237.

222 ssize_t vfs_read(struct file *file, char __user *buf, size_t count,
                    loff_t *pos)
[...]
237                         if (file->f_op->read)
238                                 ret = file->f_op->read(file, buf,
                                                           count, pos);

Sincerly,

Thomas
-- 
Thomas Petazzoni
thomas.petazzoni@xxxxxxxx

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux