void
vm_swapfile_close(uint64_t path_addr, vnode_t vp)
{
	struct nameidata nd;
	vfs_context_t context = vfs_context_current();
	int error = 0;

	vnode_getwithref(vp);
	vnode_close(vp, 0, context);
	
	NDINIT(&nd, DELETE, OP_UNLINK, AUDITVNPATH1, UIO_SYSSPACE,
	       path_addr, context);

	error = unlink1(context, &nd, 0);
}
void
vm_swapfile_close(uint64_t path_addr, vnode_t vp)
{
	vfs_context_t context = vfs_context_current();
	int error;

	vnode_getwithref(vp);
	vnode_close(vp, 0, context);
	
	error = unlink1(context, NULLVP, CAST_USER_ADDR_T(path_addr),
	    UIO_SYSSPACE, 0);

#if DEVELOPMENT || DEBUG
	if (error)
		printf("%s : unlink of %s failed with error %d", __FUNCTION__,
		    (char *)path_addr, error);
#endif
}
Exemple #3
0
int
main(int argc, char *argv[])
{
  int pid, i;

  if(argc != 3){
    fprintf(stderr, "Usage: test-lab-2-a dir1 dir2\n");
    exit(1);
  }

  sprintf(d1, "%s/d%d", argv[1], getpid());
  if(mkdir(d1, 0777) != 0){
    fprintf(stderr, "test-lab-2-a: failed: mkdir(%s): %s\n",
            d1, strerror(errno));
    exit(1);
  }
  sprintf(d2, "%s/d%d", argv[2], getpid());
  if(access(d2, 0) != 0){
    fprintf(stderr, "test-lab-2-a: failed: access(%s) after mkdir %s: %s\n",
            d2, d1, strerror(errno));
    exit(1);
  }

  setbuf(stdout, 0);

  for(i = 0; i < sizeof(big)-1; i++)
    big[i] = 'x';
  for(i = 0; i < sizeof(huge)-1; i++)
    huge[i] = '0';

  //addddddddddddd
  printf("Concurrent creates: ");
  pid = fork();
  if(pid < 0){
    perror("test-lab-2-a: fork");
    exit(1);
  }
  if(pid == 0){
    createn(d2, "xx", 20, false);
    exit(0);
  }
  createn(d1, "yy", 20, false);
  sleep(10);
  reap(pid);
  dircheck(d1, 40);
  checkn(d1, "xx", 20);
  checkn(d2, "yy", 20);
  unlinkn(d1, "xx", 20);
  unlinkn(d1, "yy", 20);
  printf("OK\n");

  printf("Concurrent create/delete: ");
  createn(d1, "x1", 20, false);
  createn(d2, "x2", 20, false);
  pid = fork();
  if(pid < 0){
    perror("test-lab-2-a: fork");
    exit(1);
  }
  if(pid == 0){
    unlinkn(d2, "x1", 20);
    createn(d1, "x3", 20, false);
    exit(0);
  }
  createn(d1, "x4", 20, false);
  reap(pid);
  unlinkn(d2, "x2", 20);
  unlinkn(d2, "x4", 20);
  unlinkn(d2, "x3", 20);
  dircheck(d1, 0);
  printf("OK\n");
  //additional
  printf("Create then read: ");
  create1(d1, "f1", "aaa");
  check1(d2, "f1", "aaa");
  check1(d1, "f1", "aaa");
  printf("OK\n");

  printf("Unlink: ");
  unlink1(d2, "f1");
  create1(d1, "fx1", "fxx"); /* checknot f1 fails w/o these */
  unlink1(d1, "fx1");
  checknot(d1, "f1");
  checknot(d2, "f1");
  create1(d1, "f2", "222");
  unlink1(d2, "f2");
  checknot(d1, "f2");
  checknot(d2, "f2");
  create1(d1, "f3", "333");
  check1(d2, "f3", "333");
  check1(d1, "f3", "333");
  unlink1(d1, "f3");
  create1(d2, "fx2", "22"); /* checknot f3 fails w/o these */
  unlink1(d2, "fx2");
  checknot(d2, "f3");
  checknot(d1, "f3");
  printf("OK\n");

  printf("Append: ");
  create1(d2, "f1", "aaa");
  append1(d1, "f1", "bbb");
  append1(d2, "f1", "ccc");
  check1(d1, "f1", "aaabbbccc");
  check1(d2, "f1", "aaabbbccc");
  printf("OK\n");

  printf("Readdir: ");
  dircheck(d1, 1);
  dircheck(d2, 1);
  unlink1(d1, "f1");
  dircheck(d1, 0);
  dircheck(d2, 0);
  create1(d2, "f2", "aaa");
  create1(d1, "f3", "aaa");
  dircheck(d1, 2);
  dircheck(d2, 2);
  unlink1(d2, "f2");
  dircheck(d2, 1);
  dircheck(d1, 1);
  unlink1(d2, "f3");
  dircheck(d1, 0);
  dircheck(d2, 0);
  printf("OK\n");

  printf("Many sequential creates: ");
  createn(d1, "aa", 10, false);
  createn(d2, "bb", 10, false);
  dircheck(d2, 20);
  checkn(d2, "bb", 10);
  checkn(d2, "aa", 10);
  checkn(d1, "aa", 10);
  checkn(d1, "bb", 10);
  unlinkn(d1, "aa", 10);
  unlinkn(d2, "bb", 10);
  printf("OK\n");

  printf("Write 20000 bytes: ");
  create1(d1, "bf", big);
  check1(d1, "bf", big);
  check1(d2, "bf", big);
  unlink1(d1, "bf");
  printf("OK\n");

  printf("Concurrent creates: ");
  pid = fork();
  if(pid < 0){
    perror("test-lab-2-a: fork");
    exit(1);
  }
  if(pid == 0){
    createn(d2, "xx", 20, false);
    exit(0);
  }
  createn(d1, "yy", 20, false);
  sleep(10);
  reap(pid);
  dircheck(d1, 40);
  checkn(d1, "xx", 20);
  checkn(d2, "yy", 20);
  unlinkn(d1, "xx", 20);
  unlinkn(d1, "yy", 20);
  printf("OK\n");

  printf("Concurrent creates of the same file: ");
  pid = fork();
  if(pid < 0){
    perror("test-lab-2-a: fork");
    exit(1);
  }
  if(pid == 0){
    createn(d2, "zz", 20, true);
    exit(0);
  }
  createn(d1, "zz", 20, true);
  sleep(4);
  dircheck(d1, 20);
  reap(pid);
  checkn(d1, "zz", 20);
  checkn(d2, "zz", 20);
  unlinkn(d1, "zz", 20);
  printf("OK\n");

  printf("Concurrent create/delete: ");
  createn(d1, "x1", 20, false);
  createn(d2, "x2", 20, false);
  pid = fork();
  if(pid < 0){
    perror("test-lab-2-a: fork");
    exit(1);
  }
  if(pid == 0){
    unlinkn(d2, "x1", 20);
    createn(d1, "x3", 20, false);
    exit(0);
  }
  createn(d1, "x4", 20, false);
  reap(pid);
  unlinkn(d2, "x2", 20);
  unlinkn(d2, "x4", 20);
  unlinkn(d2, "x3", 20);
  dircheck(d1, 0);
  printf("OK\n");

  printf("Concurrent creates, same file, same server: ");
  pid = fork();
  if(pid < 0){
    perror("test-lab-2-a: fork");
    exit(1);
  }
  if(pid == 0){
    createn(d1, "zz", 20, true);
    exit(0);
  }
  createn(d1, "zz", 20, true);
  sleep(2);
  dircheck(d1, 20);
  reap(pid);
  checkn(d1, "zz", 20);
  unlinkn(d1, "zz", 20);
  printf("OK\n");

  printf("Concurrent writes to different parts of same file: ");
  create1(d1, "www", huge);
  pid = fork();
  if(pid < 0){
    perror("test-lab-2-a: fork");
    exit(1);
  }
  if(pid == 0){
    write1(d2, "www", 65536, 64, '2');
    exit(0);
  }
  write1(d1, "www", 0, 64, '1');
  reap(pid);
  checkread(d1, "www", 0, 64, '1');
  checkread(d2, "www", 0, 64, '1');
  checkread(d1, "www", 65536, 64, '2');
  checkread(d2, "www", 65536, 64, '2');
  printf("OK\n");

  printf("test-lab-2-a: Passed all tests.\n");

  exit(0);
  return(0);
}