summaryrefslogtreecommitdiff
path: root/user/usertests.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2022-08-23 12:26:26 -0400
committerRobert Morris <[email protected]>2022-08-23 12:26:26 -0400
commit7c1810e1ae9268581de6bec30cdb696c25bae030 (patch)
treef0f68318d2e0a6f4f24479fff7880557f2f262ad /user/usertests.c
parent948cfbdb1ff8af3924fe149960824d601df13163 (diff)
downloadxv6-labs-7c1810e1ae9268581de6bec30cdb696c25bae030.tar.gz
xv6-labs-7c1810e1ae9268581de6bec30cdb696c25bae030.tar.bz2
xv6-labs-7c1810e1ae9268581de6bec30cdb696c25bae030.zip
tolerate running out of inodes
Diffstat (limited to 'user/usertests.c')
-rw-r--r--user/usertests.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/user/usertests.c b/user/usertests.c
index 23a5048..4f183a5 100644
--- a/user/usertests.c
+++ b/user/usertests.c
@@ -2750,6 +2750,7 @@ diskfull(char *s)
unlink(name);
int fd = open(name, O_CREATE|O_RDWR|O_TRUNC);
if(fd < 0){
+ // oops, ran out of inodes before running out of blocks.
printf("%s: could not create file %s\n", s, name);
done = 1;
break;
@@ -2767,7 +2768,8 @@ diskfull(char *s)
// now that there are no free blocks, test that dirlink()
// merely fails (doesn't panic) if it can't extend
- // directory content.
+ // directory content. one of these file creations
+ // is expected to fail.
int nzz = 128;
for(int i = 0; i < nzz; i++){
char name[32];
@@ -2778,14 +2780,15 @@ diskfull(char *s)
name[4] = '\0';
unlink(name);
int fd = open(name, O_CREATE|O_RDWR|O_TRUNC);
- if(fd < 0){
- printf("%s: could not create file %s\n", s, name);
+ if(fd < 0)
break;
- }
close(fd);
}
- mkdir("diskfulldir");
+ // this mkdir() is expected to fail.
+ if(mkdir("diskfulldir") == 0)
+ printf("%s: mkdir(diskfulldir) unexpectedly succeeded!\n");
+
unlink("diskfulldir");
for(int i = 0; i < nzz; i++){
@@ -2809,6 +2812,37 @@ diskfull(char *s)
}
}
+void
+outofinodes(char *s)
+{
+ int nzz = 32*32;
+ for(int i = 0; i < nzz; i++){
+ char name[32];
+ name[0] = 'z';
+ name[1] = 'z';
+ name[2] = '0' + (i / 32);
+ name[3] = '0' + (i % 32);
+ name[4] = '\0';
+ unlink(name);
+ int fd = open(name, O_CREATE|O_RDWR|O_TRUNC);
+ if(fd < 0){
+ // failure is eventually expected.
+ break;
+ }
+ close(fd);
+ }
+
+ for(int i = 0; i < nzz; i++){
+ char name[32];
+ name[0] = 'z';
+ name[1] = 'z';
+ name[2] = '0' + (i / 32);
+ name[3] = '0' + (i % 32);
+ name[4] = '\0';
+ unlink(name);
+ }
+}
+
//
// use sbrk() to count how many free physical memory pages there are.
// touches the pages to force allocation.
@@ -2986,6 +3020,7 @@ main(int argc, char *argv[])
{badarg, "badarg" },
{execout, "execout"},
{diskfull, "diskfull"},
+ {outofinodes, "outofinodes"},
{ 0, 0},
};