]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - zfs/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 2012 by Delphix. All rights reserved.
32 * --------------------------------------------------------------------
33 * The purpose of this test is to see if the bug reported (#4723351) for
34 * UFS exists when using a ZFS file system.
35 * --------------------------------------------------------------------
44 #include <sys/types.h>
50 static const int TRUE
= 1;
51 static char *filebase
;
56 return (random() % 1000);
66 len
= strlen(filebase
) + 5;
70 (void) snprintf(buf
, len
, "%s.%03d", filebase
, idx
);
71 ret
= rename(filebase
, buf
);
72 if (ret
< 0 && errno
!= ENOENT
)
73 (void) perror("renaming file");
86 len
= strlen(filebase
) + 5;
90 (void) snprintf(buf
, len
, "%s.%03d", filebase
, idx
);
92 if (ret
< 0 && errno
!= ENOENT
)
93 (void) perror("removing file");
109 *fd
= open(filebase
, O_APPEND
| O_RDWR
| O_CREAT
, 0644);
111 perror("fail to open test file, refreshing it");
115 ret
= write(*fd
, "test\n", 5);
117 perror("writing file");
124 main(int argc
, char **argv
)
130 (void) printf("Usage: %s <filebase>\n", argv
[0]);
135 fd
= open(filebase
, O_APPEND
| O_RDWR
| O_CREAT
, 0644);
137 perror("creating test file");
141 (void) pthread_setconcurrency(4); /* 3 threads + main */
142 (void) pthread_create(&tid
, NULL
, mover
, NULL
);
143 (void) pthread_create(&tid
, NULL
, cleaner
, NULL
);
144 (void) pthread_create(&tid
, NULL
, writer
, (void *) &fd
);
150 ret
= stat(filebase
, &st
);
151 if (ret
== 0 && (st
.st_nlink
> 2 || st
.st_nlink
< 1)) {
152 (void) printf("st.st_nlink = %d, exiting\n", \