4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <sys/types.h>
33 #include <sys/param.h>
37 #include <rpcsvc/nlm_prot.h>
39 #include <sys/systeminfo.h>
41 #include <nss_dbdefs.h>
44 #include <nfs/export.h>
45 #include <nfs/nfssys.h>
49 extern int _nfssys(enum nfssys_op
, void *);
51 static int share_zap(char *, char *);
54 * Clear locks and v4 related state held by
58 nfs4_clr_state(char *client
)
61 char he_buf
[NSS_BUFLEN_HOSTS
];
62 struct hostent host_ent
, *he
;
64 struct nfs4clrst_args arg
;
66 if ((he
= gethostbyname_r(client
, &host_ent
, he_buf
, sizeof (he_buf
),
67 &he_error
)) == NULL
) {
68 (void) fprintf(stderr
,
69 gettext("client name '%s' can not be resolved\n"),
75 perror("gethostbyname");
80 * The NFS4 clear state interface is
81 * versioned in case we need to pass
82 * more information in the future.
84 arg
.vers
= NFS4_CLRST_VERSION
;
85 arg
.addr_type
= he
->h_addrtype
;
88 * Iterate over IP Addresses clear
91 for (ap
= he
->h_addr_list
; *ap
; ap
++) {
93 _nfssys(NFS4_CLR_STATE
, &arg
);
99 main(int argc
, char *argv
[])
104 char myhostname
[MAXHOSTNAMELEN
];
106 if (geteuid() != (uid_t
)0) {
107 (void) fprintf(stderr
, gettext("clear_locks: must be root\n"));
111 (void) setlocale(LC_ALL
, "");
113 #if !defined(TEXT_DOMAIN)
114 #define TEXT_DOMAIN "SYS_TEST"
116 (void) textdomain(TEXT_DOMAIN
);
119 * Get the official hostname for this host
121 sysinfo(SI_HOSTNAME
, myhostname
, sizeof (myhostname
));
123 while ((c
= getopt(argc
, argv
, "s")) != EOF
) {
134 if (errflg
|| i
!= 1) {
135 (void) fprintf(stderr
,
136 gettext("Usage: clear_locks [-s] hostname\n"));
141 (void) fprintf(stdout
,
142 gettext("Clearing locks held for NFS client %s on server %s\n"),
143 myhostname
, argv
[optind
]);
144 ret
= share_zap(myhostname
, argv
[optind
]);
146 (void) fprintf(stdout
,
147 gettext("Clearing locks held for NFS client %s on server %s\n"),
148 argv
[optind
], myhostname
);
149 ret
= share_zap(argv
[optind
], myhostname
);
150 ret
+= nfs4_clr_state(argv
[optind
]);
158 * Request that host 'server' free all locks held by
162 share_zap(char *client
, char *server
)
164 struct nlm_notify notify
;
168 notify
.name
= client
;
169 rslt
= rpc_call(server
, NLM_PROG
, NLM_VERSX
, NLM_FREE_ALL
,
170 xdr_nlm_notify
, (char *)¬ify
, xdr_void
, 0, NULL
);
171 if (rslt
!= RPC_SUCCESS
) {
175 (void) fprintf(stderr
,
176 gettext("clear of locks held for %s on %s returned success\n"),