-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vfs: introduce --atime-mode option to control atime update behavior
Currently juicefs doesn't update atime on access, so introduce --atime-mode option to select how to update atime. And support three modes: - noatime: don't update atime - relatime: update atime relative to motify or change time - strictatime: always update atime Fixes: #3240 Signed-off-by: Eryu Guan <[email protected]>
- Loading branch information
Showing
14 changed files
with
420 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* JuiceFS, Copyright 2023 Juicedata, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package meta | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestRelatimeNeedUpdate(t *testing.T) { | ||
attr := &Attr{ | ||
Atime: 1000, | ||
} | ||
if !relatimeNeedUpdate(attr, time.Now()) { | ||
t.Fatal("atime not updated for 24 hours") | ||
} | ||
|
||
now := time.Now() | ||
attr.Atime = now.Unix() | ||
attr.Ctime = now.Unix() + 10 | ||
if !relatimeNeedUpdate(attr, time.Now()) { | ||
t.Fatal("atime not updated for ctime") | ||
} | ||
|
||
now = time.Now() | ||
attr.Atime = now.Unix() | ||
attr.Mtime = now.Unix() + 10 | ||
if !relatimeNeedUpdate(attr, time.Now()) { | ||
t.Fatal("atime not updated for mtime") | ||
} | ||
|
||
now = time.Now() | ||
attr.Atime = now.Unix() | ||
attr.Mtime = now.Unix() | ||
attr.Ctime = now.Unix() | ||
if relatimeNeedUpdate(attr, now) { | ||
t.Fatal("atime should not be updated") | ||
} | ||
} | ||
|
||
func TestAtimeNeedsUpdate(t *testing.T) { | ||
m := &baseMeta{ | ||
conf: &Config{ | ||
AtimeMode: NoAtime, | ||
}, | ||
} | ||
attr := &Attr{ | ||
Atime: 1000, | ||
} | ||
if m.atimeNeedsUpdate(attr, time.Now()) { | ||
t.Fatal("atime updated for noatime") | ||
} | ||
|
||
m.conf.AtimeMode = RelAtime | ||
if !m.atimeNeedsUpdate(attr, time.Now()) { | ||
t.Fatal("atime not updated for relatime") | ||
} | ||
attr.Atime = time.Now().Unix() | ||
if m.atimeNeedsUpdate(attr, time.Now()) { | ||
t.Fatal("atime updated for relatime") | ||
} | ||
|
||
m.conf.AtimeMode = StrictAtime | ||
if !m.atimeNeedsUpdate(attr, time.Now()) { | ||
t.Fatal("atime not updated for strictatime") | ||
} | ||
} |
Oops, something went wrong.