Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

4.8. 数据日志

Ordinarily, GFS2 writes only metadata to its journal. File contents are subsequently written to disk by the kernel's periodic sync that flushes file system buffers. An fsync() call on a file causes the file's data to be written to disk immediately. The call returns when the disk reports that all data is safely written.
数据日志可缩短非常小的文件的 fsync() 时间,因为文件数据在写入元数据外还要写入日志。随着文件的增大这个优势会明显降低。写入中等到大文件时打开数据日志会非常慢。
依赖 fsync() 同步文件数据的应用程序可能因使用数据日志而使性能有所提高。在被标记的目录及其所有子目录中生成的 GFS2 文件可自动启用数据日志。现有长度为 0 的文件也可以打开或者关闭其数据日志功能。
Enabling data journaling on a directory sets the directory to "inherit jdata", which indicates that all files and directories subsequently created in that directory are journaled. You can enable and disable data journaling on a file with the chattr command.
下面的命令在 /mnt/gfs2/gfs2_dir/newfile 文件中启用了数据日志,并查看是否正确设定了标签。
[root@roth-01 ~]# chattr +j /mnt/gfs2/gfs2_dir/newfile
[root@roth-01 ~]# lsattr /mnt/gfs2/gfs2_dir
---------j--- /mnt/gfs2/gfs2_dir/newfile
以下命令禁用了 /mnt/gfs2/gfs2_dir/newfile 文件中的数据日志,并查看是否正确设定了标签。
[root@roth-01 ~]# chattr -j /mnt/gfs2/gfs2_dir/newfile
[root@roth-01 ~]# lsattr /mnt/gfs2/gfs2_dir
------------- /mnt/gfs2/gfs2_dir/newfile
您还可以使用 chattr 命令在目录中设定 j 标签。当您为某个目录设定此标签时,以后在那个目录中创建的所有文件和目录也都会进行日志操作。下面的一组命令可在 gfs2_dir 目录中设定 j 标签,然后查看是否正确设定了该标签。此后,该命令会在 /mnt/gfs2/gfs2_dir 目录中生成一个名为 newfile 新文件,然后查看是否将为该文件设定了 j 标签。因为为该目录设定了 j 标签,那么应该也为 newfile 启用了日志操作。
[root@roth-01 ~]# chattr -j /mnt/gfs2/gfs2_dir
[root@roth-01 ~]# lsattr /mnt/gfs2
---------j--- /mnt/gfs2/gfs2_dir
[root@roth-01 ~]# touch /mnt/gfs2/gfs2_dir/newfile
[root@roth-01 ~]# lsattr /mnt/gfs2/gfs2_dir
---------j--- /mnt/gfs2/gfs2_dir/newfile