ディレクトリ配下でのNOATIME


bind mountのmntオプションは多重階層マウントのMS_RECのみで、他のmntオプションでのbind mountはできず、しかもmount後の属性変更はMS_SHARED | MS_PRIVATE | MS_SLAVE | MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE MS_UNBINDABLEのみで、MS_NOATIME等の他の属性変更はremountしなければならない。

サンプル

[root@localhost north]# mount /dev/sda7 /mnt7
[root@localhost north]# mount
 :
/dev/sda7 on /mnt7 type ext3 (rw,relatime,data=ordered)

[root@localhost mnt7]# mkdir dir1
[root@localhost mnt7]# mkdir dir2
[root@localhost mnt7]# mount --bind dir1 dir1
[root@localhost mnt7]# mount -o noatime,remount dir1

[root@localhost mnt7]# touch dir1/txt
[root@localhost mnt7]# touch dir2/txt

[root@localhost mnt7]# stat dir1/txt
Access: 2017-08-21 18:38:25.572974386 +0900
Modify: 2017-08-21 18:38:25.572974386 +0900
Change: 2017-08-21 18:38:25.572974386 +0900

[root@localhost mnt7]# stat dir2/txt
Access: 2017-08-21 18:38:31.035073249 +0900
Modify: 2017-08-21 18:38:31.035073249 +0900
Change: 2017-08-21 18:38:31.035073249 +0900

[root@localhost mnt7]# echo abc > dir1/txt 
[root@localhost mnt7]# stat dir1/txt
Access: 2017-08-21 18:38:25.572974386 +0900
Modify: 2017-08-21 18:40:46.378544394 +0900 
Change: 2017-08-21 18:40:46.378544394 +0900 
[root@localhost mnt7]# cat dir1/txt
abc
[root@localhost mnt7]# stat dir1/txt
Access: 2017-08-21 18:38:25.572974386 +0900         <- atime更新されない
Modify: 2017-08-21 18:40:46.378544394 +0900
Change: 2017-08-21 18:40:46.378544394 +0900

[root@localhost mnt7]# echo abc > dir2/txt 
[root@localhost mnt7]# stat dir2/txt
Access: 2017-08-21 18:38:31.035073249 +0900
Modify: 2017-08-21 18:40:53.605680804 +0900
Change: 2017-08-21 18:40:53.605680804 +0900
[root@localhost mnt7]# cat dir2/txt
abc
[root@localhost mnt7]# stat dir2/txt
Access: 2017-08-21 18:42:28.256467310 +0900         <- atime更新
Modify: 2017-08-21 18:40:53.605680804 +0900
Change: 2017-08-21 18:40:53.605680804 +0900

カーネル

long do_mount(const char *dev_name, const char *dir_name,
               const char *type_page, unsigned long flags, void *data_page)
{
       struct path path;
       int retval = 0;
       int mnt_flags = 0;

       if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
               flags &= ~MS_MGC_MSK;

       if (!dir_name || !*dir_name || !memchr(dir_name, 0, PAGE_SIZE))
               return -EINVAL;

       if (data_page)
               ((char *)data_page)[PAGE_SIZE - 1] = 0;

       retval = kern_path(dir_name, LOOKUP_FOLLOW, &path);
       if (retval)
               return retval;

       retval = security_sb_mount(dev_name, &path,
                                  type_page, flags, data_page);
       if (retval)
               goto dput_out;

       if (!(flags & MS_NOATIME))
               mnt_flags |= MNT_RELATIME;

      if (flags & MS_NOSUID)
               mnt_flags |= MNT_NOSUID;
       if (flags & MS_NODEV)
               mnt_flags |= MNT_NODEV;
       if (flags & MS_NOEXEC)
               mnt_flags |= MNT_NOEXEC;
       if (flags & MS_NOATIME)
               mnt_flags |= MNT_NOATIME;
       if (flags & MS_NODIRATIME)
               mnt_flags |= MNT_NODIRATIME;
       if (flags & MS_STRICTATIME)
               mnt_flags &= ~(MNT_RELATIME | MNT_NOATIME);
       if (flags & MS_RDONLY)
               mnt_flags |= MNT_READONLY;

       flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
                  MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
                  MS_STRICTATIME);

       if (flags & MS_REMOUNT)
               retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
                                   data_page);
       else if (flags & MS_BIND)
               retval = do_loopback(&path, dev_name, flags & MS_REC);
       else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
               retval = do_change_type(&path, flags);
       else if (flags & MS_MOVE)
               retval = do_move_mount(&path, dev_name);
       else
               retval = do_new_mount(&path, type_page, flags, mnt_flags,
                                     dev_name, data_page);
dput_out:
       path_put(&path);
       return retval;
}

備考

dir1/dir2のvfsmountは共有されていますが、mount --bind dir1 dir1は、dir1のvfsmountを重複したvfsmntのmntで、従ってdir1のvfsmountの属性変更は、dir2のvfsmountに影響されません。

最終更新 2017/08/22 18:40:09 - north
(2017/08/22 18:40:09 作成)


検索

アクセス数
3576044
最近のコメント
コアダンプファイル - sakaia
list_head構造体 - yocto_no_yomikata
勧告ロックと強制ロック - wataash
LKMからのファイル出力 - 重松 宏昌
kprobe - ななし
ksetの実装 - スーパーコピー
カーネルスレッドとは - ノース
カーネルスレッドとは - nbyst
asmlinkageってなに? - ノース
asmlinkageってなに? - よろしく
Adsense
広告情報が設定されていません。