team-ljyzipelo

공개

임시 용량 시험에서 닫힌 파일도 집계함

작성자
시로사키 하나
작성 시각
커밋
4b1f89fd40b1cc0228b4317fa0daf731f5cf62f6
부모
ceea4c1
이 시점의 파일 보기

변경된 파일 2개

+113-43
수정tests/rust-archive-worker/spool_fallback.rs+66-29
@@ -684,58 +684,95 @@ fn source_change_during_direct_read_prevents_success() {
684684}
685685
686686#[test]
687삭제: fn small_temporary_quota_lists_and_previews_large_zip_and_seven_zip() {
688삭제: for named in [false, true] {
689삭제: let c = Case::new();
690삭제: let library = c.library();
691삭제: let probe = Command::new("python3")
692삭제: .arg("-B")
693삭제: .arg("-c")
694삭제: .arg(
695삭제: r#"
687추가: fn small_temporary_quota_counts_closed_files_until_unlinked() {
688추가: let scratch = Scratch::new();
689추가: fs::create_dir(scratch.0.join("system")).unwrap();
690추가: let c = Case {
691추가: scratch,
692추가: archive_names: Vec::new(),
693추가: };
694추가: let library = c.library();
695추가: let probe = Command::new("python3")
696추가: .arg("-B")
697추가: .arg("-c")
698추가: .arg(
699추가: r#"
696700import errno, os, sys
697701from pathlib import Path
698702root = Path(sys.argv[1])
703추가: def assert_full(fd):
704추가: try:
705추가: os.write(fd, b"x")
706추가: except OSError as error:
707추가: assert error.errno == errno.ENOSPC
708추가: else:
709추가: raise AssertionError("임시 용량이 너무 일찍 반환됨")
699710a = os.open(root / "quota-a", os.O_CREAT | os.O_RDWR, 0o600)
700711b = os.open(root / "quota-b", os.O_CREAT | os.O_RDWR, 0o600)
701712duplicate = os.dup(a)
702713try:
703714 assert os.write(a, bytes(1024 * 1024)) == 1024 * 1024
715추가: os.close(duplicate)
716추가: duplicate = -1
717추가: os.close(a)
718추가: a = -1
704719 assert os.write(b, bytes(2 * 1024 * 1024)) == 1024 * 1024
705720 try:
706721 os.write(b, b"x")
707722 except OSError as error:
708723 assert error.errno == errno.ENOSPC
709724 else:
710삭제: raise AssertionError("공유 임시 용량 한도가 적용되지 않음")
725추가: raise AssertionError("닫힌 파일의 용량이 반환됨")
726추가: assert (root / "quota-a").stat().st_size == 1024 * 1024
727추가: os.link(root / "quota-a", root / "quota-alias")
728추가: (root / "quota-a").unlink()
729추가: assert_full(b)
730추가: (root / "quota-alias").unlink()
731추가: assert os.write(b, bytes(1024 * 1024)) == 1024 * 1024
732추가: duplicate = os.dup(b)
733추가: (root / "quota-b").unlink()
734추가: assert_full(b)
735추가: os.close(b)
736추가: b = -1
737추가: assert_full(duplicate)
711738 os.close(duplicate)
712739 duplicate = -1
713삭제: os.close(a)
714삭제: a = -1
715삭제: (root / "quota-a").unlink()
716삭제: assert os.write(b, b"x") == 1
740추가: b = os.open(root / "quota-b", os.O_CREAT | os.O_RDWR, 0o600)
741추가: assert os.write(b, bytes(2 * 1024 * 1024)) == 2 * 1024 * 1024
717742finally:
718743 if duplicate >= 0:
719744 os.close(duplicate)
720745 if a >= 0:
721746 os.close(a)
722삭제: os.close(b)
723삭제: for name in ["quota-a", "quota-b"]:
747추가: if b >= 0:
748추가: os.close(b)
749추가: for name in ["quota-a", "quota-b", "quota-alias"]:
724750 (root / name).unlink(missing_ok=True)
725751"#,
726삭제: )
727삭제: .arg(c.scratch.0.join("system"))
728삭제: .env("LD_PRELOAD", library)
729삭제: .env("ZIPELO_SPOOL_PHASE", "tiny-tmpfs")
730삭제: .env("ZIPELO_SPOOL_TRACE", c.scratch.0.join("trace"))
731삭제: .output()
732삭제: .unwrap();
733삭제: assert!(probe.status.success(), "{:?}", probe.stderr);
734삭제: assert!(
735삭제: fs::read_to_string(c.scratch.0.join("trace"))
736삭제: .unwrap()
737삭제: .contains('F')
738삭제: );
752추가: )
753추가: .arg(c.scratch.0.join("system"))
754추가: .env("TMPDIR", c.scratch.0.join("system"))
755추가: .env("LD_PRELOAD", library)
756추가: .env("ZIPELO_SPOOL_PHASE", "tiny-tmpfs")
757추가: .env("ZIPELO_SPOOL_TRACE", c.scratch.0.join("trace"))
758추가: .output()
759추가: .unwrap();
760추가: assert!(
761추가: probe.status.success(),
762추가: "{}",
763추가: String::from_utf8_lossy(&probe.stderr)
764추가: );
765추가: assert!(
766추가: fs::read_to_string(c.scratch.0.join("trace"))
767추가: .unwrap()
768추가: .contains('F')
769추가: );
770추가: }
771추가:
772추가: #[test]
773추가: fn small_temporary_quota_lists_and_previews_large_zip_and_seven_zip() {
774추가: for named in [false, true] {
775추가: let c = Case::new();
739776 for format in ["zip", "7z"] {
740777 c.assert_preview(format, "tiny-tmpfs", 0, named);
741778 }
수정tests/rust-archive-worker/spool_location_fault.c+47-14
@@ -61,31 +61,64 @@ static void trace(int at) {
6161 close(fd);
6262 }
6363}
64추가: struct usage {
65추가: struct stat seen[256];
66추가: size_t count;
67추가: unsigned long long bytes;
68추가: };
69추가: static void count_file(struct usage *usage, const struct stat *value) {
70추가: if (!S_ISREG(value->st_mode)) return;
71추가: for (size_t i = 0; i < usage->count; i++) {
72추가: if (usage->seen[i].st_dev == value->st_dev
73추가: && usage->seen[i].st_ino == value->st_ino) return;
74추가: }
75추가: if (usage->count == 256) _exit(97);
76추가: usage->seen[usage->count++] = *value;
77추가: usage->bytes += value->st_size;
78추가: }
79추가: static void count_directory(DIR *directory, struct usage *usage, unsigned depth) {
80추가: if (depth > 64) _exit(97);
81추가: struct dirent *entry;
82추가: while ((entry = readdir(directory))) {
83추가: if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) continue;
84추가: struct stat value;
85추가: if (fstatat(dirfd(directory), entry->d_name, &value, AT_SYMLINK_NOFOLLOW)) _exit(98);
86추가: count_file(usage, &value);
87추가: if (S_ISDIR(value.st_mode)) {
88추가: int fd = original_openat(dirfd(directory), entry->d_name,
89추가: O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
90추가: if (fd < 0) _exit(98);
91추가: DIR *child = fdopendir(fd);
92추가: if (!child) _exit(98);
93추가: count_directory(child, usage, depth + 1);
94추가: closedir(child);
95추가: }
96추가: }
97추가: }
6498static unsigned long long temporary_usage(void) {
65삭제: DIR *directory = opendir("/proc/self/fd");
99추가: struct usage usage = {0};
100추가: const char *root = getenv("TMPDIR");
101추가: if (!root) _exit(98);
102추가: DIR *directory = opendir(root);
103추가: if (!directory) _exit(98);
104추가: // 닫혀도 이름이 남은 파일은 계속 용량을 사용함.
105추가: count_directory(directory, &usage, 0);
106추가: closedir(directory);
107추가: directory = opendir("/proc/self/fd");
66108 if (!directory) _exit(98);
67109 struct dirent *entry;
68삭제: struct stat seen[256];
69삭제: size_t count = 0;
70삭제: unsigned long long used = 0;
110추가: // 이름이 지워진 열린 파일도 마지막 핸들을 닫기 전까지 집계함.
71111 while ((entry = readdir(directory))) {
72112 if (entry->d_name[0] == '.') continue;
73113 int fd = atoi(entry->d_name);
74114 char path[4096];
75115 struct stat value;
76삭제: if (descriptor(fd, path, sizeof(path)) != 2 || fstat(fd, &value)
77삭제: || !S_ISREG(value.st_mode)) continue;
78삭제: size_t i;
79삭제: for (i = 0; i < count; i++) {
80삭제: if (seen[i].st_dev == value.st_dev && seen[i].st_ino == value.st_ino) break;
116추가: if (descriptor(fd, path, sizeof(path)) == 2 && !fstat(fd, &value)) {
117추가: count_file(&usage, &value);
81118 }
82삭제: if (i < count) continue;
83삭제: if (count == 256) _exit(97);
84삭제: seen[count++] = value;
85삭제: used += value.st_size;
86119 }
87120 closedir(directory);
88삭제: return used;
121추가: return usage.bytes;
89122}
90123static void exhausted(void) {
91124 const char *path = getenv("ZIPELO_SPOOL_TRACE");