prot_main.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 759 行 · 第 1/2 页

C
759
字号
# ifndef lintstatic char *sccsid = "@(#)prot_main.c	4.1	(ULTRIX)	7/2/90";# endif not lint/**************************************************************** *								* *  Licensed to Digital Equipment Corporation, Maynard, MA	* *		Copyright 1985 Sun Microsystems, Inc.		* *			All rights reserved.			* *								* ****************************************************************//**//* *	Modification history: *	~~~~~~~~~~~~~~~~~~~~ * *	revision			comments *	--------	----------------------------------------------- * *	01-Jun-89	Fred Glover *			Update for nfssrc 4.0 * *	18-Jan-88	fries *			Added Header and Copyright notice. * *	 */#include <stdio.h>#include <signal.h>#include <sys/file.h>#include <sys/ioctl.h>#include "prot_lock.h"#include "priv_prot.h"#include "prot_time.h"#define DEBUG_ON	17#define DEBUG_OFF	18#define KILL_IT		19int HASH_SIZE;int debug;int klm, nlm;int report_sharing_conflicts;XDR x;FILE *fp;SVCXPRT *klm_transp;			/* export klm transport handle */SVCXPRT *nlm_transp;			/* export nlm transport handle */extern int grace_period;extern msg_entry *klm_msg;	extern int lock_len, res_len;extern remote_result res_nolock;extern remote_result res_working;extern remote_result res_grace;extern reclock *get_le();extern msg_entry *queue();extern remote_result *get_res();extern int xtimer();extern void priv_prog();extern reclock *copy_le();extern struct fs_rlck *copy_fe();/* Ultrix mod - fsg */debug_exit(){	exit(2);}static voidnlm_prog(Rqstp, Transp)	struct svc_req *Rqstp;	SVCXPRT *Transp;{	bool_t (*xdr_Argument)(), (*xdr_Result)();	char *(*Local)();	extern nlm_testres *proc_nlm_test();	extern nlm_res *proc_nlm_lock();	extern nlm_res *proc_nlm_cancel();	extern nlm_res *proc_nlm_unlock();	extern nlm_res *proc_nlm_granted();	extern void *proc_nlm_test_msg();	extern void *proc_nlm_lock_msg();	extern void *proc_nlm_cancel_msg();	extern void *proc_nlm_unlock_msg();	extern void *proc_nlm_granted_msg();	extern void *proc_nlm_test_res();	extern void *proc_nlm_lock_res();	extern void *proc_nlm_cancel_res();	extern void *proc_nlm_unlock_res();	extern void *proc_nlm_granted_res();	extern void *proc_nlm_share();	extern void *proc_nlm_freeall();	int	monitor_this_lock = 1;	reclock *req;	remote_result *reply;	int oldmask;	if (debug)		printf("NLM_PROG+++ version %d proc %d\n",			Rqstp->rq_vers, Rqstp->rq_proc);	oldmask = sigblock (1 << (SIGALRM -1));	nlm_transp = Transp;		/* export the transport handle */	switch (Rqstp->rq_proc) {	case NULLPROC:		svc_sendreply(Transp, xdr_void, NULL);		(void) sigsetmask(oldmask);		return;	case DEBUG_ON:		debug = 2;		svc_sendreply(Transp, xdr_void, NULL);		(void) sigsetmask(oldmask);		return;	case DEBUG_OFF:		debug = 0;		svc_sendreply(Transp, xdr_void, NULL);		(void) sigsetmask(oldmask);		return;	case NLM_TEST:		xdr_Argument = xdr_nlm_testargs;		xdr_Result = xdr_nlm_testres;		Local = (char *(*)()) proc_nlm_test;		break;	case NLM_LOCK:		xdr_Argument = xdr_nlm_lockargs;		xdr_Result = xdr_nlm_res;		Local = (char *(*)()) proc_nlm_lock;		break;	case NLM_CANCEL:		xdr_Argument = xdr_nlm_cancargs;		xdr_Result = xdr_nlm_res;		Local = (char *(*)()) proc_nlm_cancel;		break;	case NLM_UNLOCK:		xdr_Argument = xdr_nlm_unlockargs;		xdr_Result = xdr_nlm_res;		Local = (char *(*)()) proc_nlm_unlock;		break;	case NLM_GRANTED:		xdr_Argument = xdr_nlm_testargs;		xdr_Result = xdr_nlm_res;		Local = (char *(*)()) proc_nlm_granted;		break;	case NLM_TEST_MSG:		xdr_Argument = xdr_nlm_testargs;		xdr_Result = xdr_void;		Local = (char *(*)()) proc_nlm_test_msg;		break;	case NLM_LOCK_MSG:		xdr_Argument = xdr_nlm_lockargs;		xdr_Result = xdr_void;		Local = (char *(*)()) proc_nlm_lock_msg;		break;	case NLM_CANCEL_MSG:		xdr_Argument = xdr_nlm_cancargs;		xdr_Result = xdr_void;		Local = (char *(*)()) proc_nlm_cancel_msg;		break;	case NLM_UNLOCK_MSG:		xdr_Argument = xdr_nlm_unlockargs;		xdr_Result = xdr_void;		Local = (char *(*)()) proc_nlm_unlock_msg;		break;	case NLM_GRANTED_MSG:		xdr_Argument = xdr_nlm_testargs;		xdr_Result = xdr_void;		Local = (char *(*)()) proc_nlm_granted_msg;		break;	case NLM_TEST_RES:		xdr_Argument = xdr_nlm_testres;		xdr_Result = xdr_void;		Local = (char *(*)()) proc_nlm_test_res;		break;	case NLM_LOCK_RES:		xdr_Argument = xdr_nlm_res;		xdr_Result = xdr_void;		Local = (char *(*)()) proc_nlm_lock_res;		break;	case NLM_CANCEL_RES:		xdr_Argument = xdr_nlm_res;		xdr_Result = xdr_void;		Local = (char *(*)()) proc_nlm_cancel_res;		break;	case NLM_UNLOCK_RES:		xdr_Argument = xdr_nlm_res;		xdr_Result = xdr_void;		Local = (char *(*)()) proc_nlm_unlock_res;		break;	case NLM_GRANTED_RES:		xdr_Argument = xdr_nlm_res;		xdr_Result = xdr_void;		Local = (char *(*)()) proc_nlm_granted_res;		break;	case NLM_SHARE:	case NLM_UNSHARE:		if (Rqstp->rq_vers != NLM_VERSX)  {			svcerr_noproc(Transp);			(void) sigsetmask(oldmask);			return;		}		proc_nlm_share(Rqstp, Transp);		(void) sigsetmask(oldmask);		return; 	case NLM_NM_LOCK:		if (Rqstp->rq_vers != NLM_VERSX)  {			svcerr_noproc(Transp);			(void) sigsetmask(oldmask);			return;		}		Rqstp->rq_proc = NLM_LOCK; /* fake it */		monitor_this_lock = 0;		xdr_Argument = xdr_nlm_lockargs;		xdr_Result = xdr_nlm_res;		Local = (char *(*)()) proc_nlm_lock;		break; 	case NLM_FREE_ALL:		if (Rqstp->rq_vers != NLM_VERSX)  {			svcerr_noproc(Transp);			(void) sigsetmask(oldmask);			return;		}		proc_nlm_freeall(Rqstp, Transp);		(void) sigsetmask(oldmask);		return; 	default:		svcerr_noproc(Transp);		(void) sigsetmask(oldmask);		return;	}	if ( Rqstp->rq_proc != NLM_LOCK_RES && Rqstp->rq_proc != NLM_CANCEL_RES	&& Rqstp->rq_proc != NLM_UNLOCK_RES && Rqstp->rq_proc != NLM_TEST_RES	&& Rqstp->rq_proc != NLM_GRANTED_RES) {		/* lock request */		if ((req = get_le()) != NULL) {			if (!svc_getargs(Transp, xdr_Argument, req)) {				svcerr_decode(Transp);				(void) sigsetmask(oldmask);				return;			}			if (debug == 3){			if (fwrite(&nlm, sizeof(int), 1, fp) == 0)				fprintf(stderr, "fwrite nlm error\n");			if (fwrite(&Rqstp->rq_proc, sizeof(int), 1, fp) == 0)				fprintf(stderr, "fwrite nlm_proc error\n");			(*xdr_Argument)(&x, req);			printf("range[%d, %d] \n", req->lck.l_offset, req->lck.l_len);			(void) fflush(fp);			}			if ((map_klm_nlm(req, (int) Rqstp->rq_proc)) != -1 ) {			/*			 * only lock, unlockd need to preassign le;			 * only lock needs to preassign fe;			 */				if (Rqstp->rq_proc == NLM_LOCK || Rqstp->rq_proc == NLM_LOCK_MSG 				|| Rqstp->rq_proc == NLM_UNLOCK || Rqstp->rq_proc == NLM_UNLOCK_MSG) {  									if ((req->pre_le = copy_le(req)) != NULL) {						if (Rqstp->rq_proc == NLM_LOCK || Rqstp->rq_proc == NLM_LOCK_MSG) {							if ((req->pre_fe = (char *) copy_fe(req)) == NULL)								goto abnormal;						}					}					else						goto abnormal;				}			}			else 				goto abnormal;						if (grace_period >0 && !(req->reclaim) ) {				if (debug)					printf("during grace period, please retry later\n");				nlm_reply(Rqstp->rq_proc, &res_grace, req); 				req->rel = 1;				release_le(req);				(void) sigsetmask(oldmask);				return;			}			if ( grace_period >0 && debug)				printf("accept reclaim request(%x)\n", req);			if (monitor_this_lock &&				(Rqstp->rq_proc == NLM_LOCK ||				 Rqstp->rq_proc == NLM_LOCK_MSG))				/* only monitor lock req */				if (add_mon(req, 1) == -1) {					req->rel = 1;					release_le(req);					fprintf(stderr, "req discard due status monitor problem\n");					(void) sigsetmask(oldmask);					return;				}			(*Local)(req);			release_le(req);			call_back();		/* check if req cause nlm calling klm back */			release_me();			release_fe();			if (debug)				pr_all();		}		else { /* malloc err, return nolock */			nlm_reply((int) Rqstp->rq_proc, &res_nolock, req);		}	}	else {		/* msg reply */		if ((reply = get_res()) != NULL) {			if (!svc_getargs(Transp, xdr_Argument, reply)) {				svcerr_decode(Transp);				(void) sigsetmask(oldmask);				return;			}			if (debug == 3){			if (fwrite(&nlm, sizeof(int), 1, fp) == 0)				fprintf(stderr, "fwrite nlm_reply error\n");			if (fwrite(&Rqstp->rq_proc, sizeof(int), 1, fp) == 0)				fprintf(stderr, "fwrite nlm_reply_proc error \n");			(*xdr_Argument)(&x, reply);			(void) fflush(fp);			}			if (debug)				printf("msg reply(%d) to procedure(%d)\n",				reply->lstat, Rqstp->rq_proc);			(*Local)(reply);			release_me();			release_fe();			if (debug && reply->lstat != blocking);				pr_all();		}		else {/* malloc failure, do nothing */		}	}	(void) sigsetmask(oldmask);	return;abnormal:	/* malloc error, release allocated space and error return*/	nlm_reply((int) Rqstp->rq_proc, &res_nolock, req);	req->rel = 1;	release_le(req);	(void) sigsetmask(oldmask);	return;}static voidklm_prog(Rqstp, Transp)	struct svc_req *Rqstp;	SVCXPRT *Transp;{	bool_t (*xdr_Argument)(), (*xdr_Result)();	char *(*Local)();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?