Problem: LTP linkat01 test fails on nfs directory (NFS v3)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Tested kernels: 2.6.18, 2.6.22, 2.6.23-rc2

Steps to reproduce: Suppose that we have mounted some directory from nfs v3 
server with default options. Also we  have the two directories in this 
mountpoint and each directory has hard linked file. Try to open those files 
and write to one and read from another. Data will not be equal. (Testcase: 
attached hardlink_test.c)

Analysis: Although these hard linked files have same nfs_fattr::fileid but 
have different nfs_fh fhandle. In this case nfs_find_actor() function 
(fs/nfs/inode.c) returns false during opening each file:

	if (nfs_compare_fh(NFS_FH(inode), fh))
		return 0;

Therefore for each of hard links new struct inode is allocated. It leads to 
cache aliasing.

Please explain why nfs_find_actor() function compares file handles?

Vitaliy Gusev

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

#define SLEEP 15

int main(int argc, char *argv[])
	int fd1,fd2;
	char *f1 = argv[1];
	char *f2 = argv[2];
	char buf[1000]= {0,};
	char wrbuf[200];
	int ret;

	assert(argc == 3);

	printf("write to: %s\nread from: %s\n\n",
	       f1, f2);

	fd1 = open(f1, O_RDWR);
	fd2 = open(f2, O_RDONLY);
	if (fd1 < 0 || fd2 < 0)
		err(1, "error open");
	sprintf(wrbuf, "test message-%d", getpid());
	printf("Write: [%s]\n", wrbuf);
	ret = write(fd1, wrbuf, strlen(wrbuf));
	if (ret < 0)
		err(1, "error write");

	ret = read(fd2, buf, sizeof(buf) - 1);
	if (ret < 0)
		err(1, "error read");
	printf("Read:  [%s]\n", buf);
	return 0;

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux