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 https://opensource.org/licenses/CDDL-1.0.
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) 2013 by Delphix. All rights reserved.
31 #include <sys/types.h>
42 * The size of the output file, "go.out", should be 80*8192*2 = 1310720
44 * $ cd /tmp; go; ls -l go.out
46 * -rwxr-xr-x 1 jdm staff 1310720 Apr 13 19:45 go.out
47 * $ cd /zfs; go; ls -l go.out
49 * -rwxr-xr-x 1 jdm staff 663552 Apr 13 19:45 go.out
51 * The file on zfs is short as it does not appear that zfs is making the
52 * implicit seek to EOF and the actual write atomic. From the SUSv3
53 * interface spec, behavior is undefined if concurrent writes are performed
54 * from multi-processes to a single file. So I don't know if this is a
55 * standards violation, but I cannot find any such disclaimers in our
56 * man pages. This issue came up at a customer site in another context, and
57 * the suggestion was to open the file with O_APPEND, but that wouldn't
58 * help with zfs(see 4977529). Also see bug# 5031301.
66 int ret
, i
= 0, n
= *(int *)data
;
68 (void) memset(buf
, n
, sizeof (buf
));
70 for (i
= 0; i
< 80; i
++) {
71 ret
= write(outfd
, buf
, sizeof (buf
));
72 if (ret
!= sizeof (buf
))
81 (void) fprintf(stderr
,
82 "usage: zfs_threadsappend <file name>\n");
87 main(int argc
, char **argv
)
98 ncpus
= sysconf(_SC_NPROCESSORS_ONLN
);
100 (void) fprintf(stderr
,
101 "Invalid return from sysconf(_SC_NPROCESSORS_ONLN)"
102 " : errno (decimal)=%d\n", errno
);
106 (void) fprintf(stderr
,
107 "Must execute this binary on a multi-processor system\n");
111 outfd
= open(argv
[optind
++], O_RDWR
|O_CREAT
|O_APPEND
|O_TRUNC
, 0777);
113 (void) fprintf(stderr
,
114 "zfs_threadsappend: "
115 "open(%s, O_RDWR|O_CREAT|O_APPEND|O_TRUNC, 0777)"
116 " failed\n", argv
[optind
]);
121 for (i
= 0; i
< 2; i
++) {
122 ret
= pthread_create(&tid
, NULL
, go
, (void *)&i
);
124 (void) fprintf(stderr
,
125 "zfs_threadsappend: thr_create(#%d) "
126 "failed error=%d\n", i
+1, ret
);
131 while (pthread_join(tid
, NULL
) == 0)