xref: /illumos-gate/usr/src/uts/common/nfs/lm.h (revision b819cea2)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
26bbaa8b60SDan Kruchinin /*
27*b819cea2SGordon Ross  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
28bbaa8b60SDan Kruchinin  */
29bbaa8b60SDan Kruchinin 
307c478bd9Sstevel@tonic-gate #ifndef _NFS_LM_H
317c478bd9Sstevel@tonic-gate #define	_NFS_LM_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Interface definitions for the NFSv2/v3 lock manager.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef __cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <sys/cred.h>
427c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
437c478bd9Sstevel@tonic-gate #include <sys/types.h>
447c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
45*b819cea2SGordon Ross #include <rpc/xdr.h>
467c478bd9Sstevel@tonic-gate 
47*b819cea2SGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL)
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * Common interfaces.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate 
53bbaa8b60SDan Kruchinin struct exportinfo;
54bbaa8b60SDan Kruchinin 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * The numeric sysid is used to identify a host and transport.
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  * The local locking code uses (pid, sysid) to uniquely identify a process.
597c478bd9Sstevel@tonic-gate  * This means that the client-side code must doctor up the sysid before
607c478bd9Sstevel@tonic-gate  * registering a lock, so that the local locking code doesn't confuse a
617c478bd9Sstevel@tonic-gate  * remote process with a local process just because they have the same pid.
627c478bd9Sstevel@tonic-gate  * We currently do this by ORing LM_SYSID_CLIENT into the sysid before
637c478bd9Sstevel@tonic-gate  * registering a lock.
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  * If you change LM_SYSID and LM_SYSID_MAX, be sure to pick values so that
667c478bd9Sstevel@tonic-gate  * LM_SYSID_MAX > LM_SYSID using signed arithmetic, and don't use zero.
677c478bd9Sstevel@tonic-gate  * You may also need a different way to tag lock manager locks that are
687c478bd9Sstevel@tonic-gate  * registered locally.
697c478bd9Sstevel@tonic-gate  */
707c478bd9Sstevel@tonic-gate #define	LM_SYSID	((sysid_t)0x0001)
717c478bd9Sstevel@tonic-gate #define	LM_SYSID_MAX	((sysid_t)0x3FFF)
727c478bd9Sstevel@tonic-gate #define	LM_SYSID_CLIENT	((sysid_t)0x4000)
737c478bd9Sstevel@tonic-gate #define	LM_NOSYSID	((sysid_t)-1)
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * Struct used to represent a host.
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate struct lm_sysid;
79*b819cea2SGordon Ross struct knetconfig;
80*b819cea2SGordon Ross struct netbuf;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * Given a knetconfig and network address, returns a reference to the
847c478bd9Sstevel@tonic-gate  * associated lm_sysid.  The 3rd argument is the hostname to assign to the
857c478bd9Sstevel@tonic-gate  * lm_sysid.  The 4th argument is an output parameter.  It is set non-zero
867c478bd9Sstevel@tonic-gate  * if the returned lm_sysid has a different protocol
877c478bd9Sstevel@tonic-gate  * (knetconfig::knc_proto) than what was requested.
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate extern struct lm_sysid	  *lm_get_sysid(struct knetconfig *, struct netbuf *,
907c478bd9Sstevel@tonic-gate 				char *, bool_t *);
917c478bd9Sstevel@tonic-gate extern void		   lm_rel_sysid(struct lm_sysid *);
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * Return the integer sysid for the given lm_sysid.
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate extern sysid_t		   lm_sysidt(struct lm_sysid *);
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate extern void		   lm_free_config(struct knetconfig *);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate extern void		   lm_cprsuspend(void);
1017c478bd9Sstevel@tonic-gate extern void		   lm_cprresume(void);
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate  * Client-side interfaces.
1057c478bd9Sstevel@tonic-gate  */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate extern int		   lm_frlock(struct vnode *vp, int cmd,
1087c478bd9Sstevel@tonic-gate 				struct flock64 *flk, int flag,
1097c478bd9Sstevel@tonic-gate 				u_offset_t offset, struct cred *cr,
1107c478bd9Sstevel@tonic-gate 				netobj *fh, struct flk_callback *);
1117c478bd9Sstevel@tonic-gate extern int		   lm_has_sleep(const struct vnode *);
1127c478bd9Sstevel@tonic-gate extern void		   lm_register_lock_locally(vnode_t *,
1137c478bd9Sstevel@tonic-gate 				struct lm_sysid *, struct flock64 *, int,
1147c478bd9Sstevel@tonic-gate 				u_offset_t);
1157c478bd9Sstevel@tonic-gate extern int		   lm_safelock(vnode_t *, const struct flock64 *,
1167c478bd9Sstevel@tonic-gate 				cred_t *);
1177c478bd9Sstevel@tonic-gate extern int		   lm_safemap(const vnode_t *);
1187c478bd9Sstevel@tonic-gate extern int		   lm_shrlock(struct vnode *vp, int cmd,
1197c478bd9Sstevel@tonic-gate 				struct shrlock *shr, int flag, netobj *fh);
1207c478bd9Sstevel@tonic-gate extern int		   lm4_frlock(struct vnode *vp, int cmd,
1217c478bd9Sstevel@tonic-gate 				struct flock64 *flk, int flag,
1227c478bd9Sstevel@tonic-gate 				u_offset_t offset, struct cred *cr,
1237c478bd9Sstevel@tonic-gate 				netobj *fh, struct flk_callback *);
1247c478bd9Sstevel@tonic-gate extern int		   lm4_shrlock(struct vnode *vp, int cmd,
1257c478bd9Sstevel@tonic-gate 				struct shrlock *shr, int flag, netobj *fh);
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * Server-side interfaces.
1297c478bd9Sstevel@tonic-gate  */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate extern void		   lm_unexport(struct exportinfo *);
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Clustering: functions to encode the nlmid of the node where this NLM
1357c478bd9Sstevel@tonic-gate  * server is running in the l_sysid of the flock struct or the s_sysid
1367c478bd9Sstevel@tonic-gate  * field of the shrlock struct (respectively).
1377c478bd9Sstevel@tonic-gate  */
1387c478bd9Sstevel@tonic-gate extern void		   lm_set_nlmid_flk(int *);
1397c478bd9Sstevel@tonic-gate extern void		   lm_set_nlmid_shr(int32_t *);
1407c478bd9Sstevel@tonic-gate /* Hook for deleting all mandatory NFSv4 file locks held by a remote client */
1417c478bd9Sstevel@tonic-gate extern void (*lm_remove_file_locks)(int);
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate  * The following global variable is the node id of the node where this
1457c478bd9Sstevel@tonic-gate  * NLM server is running.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate extern int lm_global_nlmid;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate  * End of clustering hooks.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * Return non-zero if the given local vnode is in use.
1557c478bd9Sstevel@tonic-gate  */
1567c478bd9Sstevel@tonic-gate extern int lm_vp_active(const struct vnode *);
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate extern sysid_t		   lm_alloc_sysidt(void);
1597c478bd9Sstevel@tonic-gate extern void		   lm_free_sysidt(sysid_t);
1607c478bd9Sstevel@tonic-gate 
161bbaa8b60SDan Kruchinin #endif /* _KERNEL */
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #ifdef __STDC__
1647c478bd9Sstevel@tonic-gate extern int lm_shutdown(void);
1657c478bd9Sstevel@tonic-gate #else
1667c478bd9Sstevel@tonic-gate extern int lm_shutdown();
1677c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate #endif
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate #endif /* _NFS_LM_H */
174