assise icon indicating copy to clipboard operation
assise copied to clipboard

Updation of number of inode links not persisted

Open OmSaran opened this issue 4 years ago • 4 comments

Consider the example scenario: A new filesystem that has only /mlfs

  1. Check the number of nlinks for /mlfs, it returns 1
  2. Create a directory /mlfs/A
  3. Check the number of nlinks again, it returns 2 (from DRAM)
  4. First 3 steps run in the same process.
  5. In a new program check the number of nlinks for /mlfs it returns 1 (This should be 2)

If my understanding is correct we have not persisted it during log digestion.

I attempted a fix for this here: #21

Here's the sample program I used to test it:

create.c

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <assert.h>

#include <mlfs/mlfs_interface.h>

#define PARENT_DIR "/mlfs"
#define CHILD_DIR "/mlfs/A"

int main() {
    init_fs();
    int ret;
    struct stat statbuf;

    lstat(PARENT_DIR, &statbuf);
    printf("nlinks before creating = %ld\n", statbuf.st_nlink);

    ret = mkdir(CHILD_DIR, 0777);
    assert(ret == 0);

    lstat(PARENT_DIR, &statbuf);
    printf("nlinks after creating = %ld\n", statbuf.st_nlink);
    shutdown_fs();
}

check.c

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <assert.h>
#include <unistd.h>

#include <mlfs/mlfs_interface.h>

#define PARENT_DIR "/mlfs"
#define CHILD_DIR "/mlfs/A"

int main() {
    init_fs();

    int ret;
    struct stat statbuf;

    ret = access(CHILD_DIR, F_OK);
    assert(ret == 0);

    printf("%s exists!\n", CHILD_DIR);

    assert(lstat(PARENT_DIR, &statbuf) == 0);
    printf("nlinks = %ld\n", statbuf.st_nlink);

    shutdown_fs();
}

OmSaran avatar Nov 19 '21 22:11 OmSaran

The access control group has had a similar issue with some custom inode params. We've been adding user/group/permission fields to the inode/stat and, although they are processed properly in-memory (e.g. mlfs_object_create) when writing to a new file, these fields revert to zero when we close and reopen the same file later. It seems like these changes aren't being conveyed to the disk during digestion.

cmolder avatar Nov 20 '21 04:11 cmolder

Based on my understanding, it is updated in the cache properly in LibFS, but during digestion, some inode updates (particularly nlinks in my case) are not being captured/digested. I guess you have the same issue after adding new attributes to the inode.

If my understanding is correct, you could attempt to add corresponding updates at the same place where I have added the fix for nlinks. The PR is here: #21

OmSaran avatar Nov 20 '21 05:11 OmSaran

Implementing #21 worked for me, at least for the other fields. Thanks!

cmolder avatar Nov 21 '21 17:11 cmolder

Thanks for the fix. This is now merged.

wreda avatar Nov 30 '21 01:11 wreda