source: gpfs_3.1_ker2.6.20/lpp/mmfs/src/ibm-linux/cxiSystem-plat.h @ 41

Last change on this file since 41 was 16, checked in by rock, 17 years ago
File size: 27.7 KB
RevLine 
[16]1/***************************************************************************
2 *
3 * Copyright (C) 2001 International Business Machines
4 * All rights reserved.
5 *
6 * This file is part of the GPFS mmfslinux kernel module.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 *  1. Redistributions of source code must retain the above copyright notice,
13 *     this list of conditions and the following disclaimer.
14 *  2. Redistributions in binary form must reproduce the above copyright
15 *     notice, this list of conditions and the following disclaimer in the
16 *     documentation and/or other materials provided with the distribution.
17 *  3. The name of the author may not be used to endorse or promote products
18 *     derived from this software without specific prior written
19 *     permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *************************************************************************** */
33/* @(#)65       1.116.1.3  src/avs/fs/mmfs/ts/kernext/ibm-linux/cxiSystem-plat.h, mmfs, avs_rgpfs24, rgpfs24s007a 10/25/06 17:52:33 */
34/*
35 * Interface definitions for basic common services, Linux version
36 *
37 * Contents:
38 *   cxiGetThreadId - get thread identifier
39 *   cxiUiomove - transfer data between kernel buffer and user buffer(s)
40 *   cxiCopyIn - copy data from user to kernel buffer (kernel service)
41 *   cxiCopyOut - copy data from kernel to user buffer (kernel service)
42 *   cxiCopyInstr - copy string from user to kernel space (kernel service)
43 *
44 */
45
46#ifndef _h_cxiSystem_plat
47#define _h_cxiSystem_plat
48
49#ifndef _h_cxiSystem
50#error Platform header (XXX-plat.h) should not be included directly
51#endif
52
53/* Size of stack to allocate for GPFS threads */
54#ifdef GPFS_ARCH_I386
55#define GPFS_STACK_SIZE (256*1024UL)
56#endif /* GPFS_ARCH_I386 */
57#ifdef GPFS_ARCH_POWER
58#define GPFS_STACK_SIZE (256*1024UL)
59#endif /* GPFS_ARCH_POWER */
60#ifdef GPFS_ARCH_IA64
61#define GPFS_STACK_SIZE (512*1024UL)
62#endif /* GPFS_ARCH_IA64 */
63#ifdef GPFS_ARCH_PPC64
64#define GPFS_STACK_SIZE (512*1024UL)
65#endif /* GPFS_ARCH_POWER */
66#ifdef GPFS_ARCH_X86_64
67#define GPFS_STACK_SIZE (512*1024UL)
68#endif /* GPFS_ARCH_POWER */
69
70/* -------------------------------------------------------------- */
71/* Interfaces usable from both kernel code and process-level code */
72/* -------------------------------------------------------------- */
73
74/* Main module device name */
75#define GPFS_DEVNAME "/dev/ss0"
76
77/* Virtual memory page size.  Used for aligning I/O buffers. */
78/* NOTE: Shark-gpl.h grabs PAGE_SIZE for the portability layer */
79#if !defined(GPFS_GPL)
80
81#ifdef GPFS_LINUX
82#if defined(GPFS_ARCH_IA64)
83/* Note that the page size can be adjusted in the IA64 Linux kernel */
84/* Newer tool chain uses getpagesize() for PAGE_SIZE, which is a problem */
85#define PAGE_SIZE 16384UL
86#else
87#include <sys/user.h>     /* PAGE_SIZE */
88#endif
89
90#if defined(GPFS_ARCH_POWER) || defined(GPFS_ARCH_PPC64)
91#ifndef PAGE_SIZE
92#define PAGE_SIZE 4096UL
93#endif
94#endif
95#endif /* GPFS_LINUX */
96
97#endif /* !GPFS_GPL */
98
99/* Process operations */
100#if !defined(GPFS_GPL)
101EXTERNC pid_t getpid() __THROW;
102#else
103/* use of THROW causes conflicts in portability kernel code */
104EXTERNC pid_t getpid();
105#endif /* !GPFS_GPL */
106
107/* Get the kernel thread ID, which is guaranteed to be non-zero.  In a
108 * process, this just calls getpid.  Within the kernel, this calls a routine
109 * that extracts the process ID from the current process block.
110 */
111#define MAX_GPFS_KERNEL_TID 32767      /* max kernel thread id (2^15 - 1) */
112
113#ifdef _KERNEL
114
115EXTERNC cxiThreadId cxiGetThreadId();
116
117EXTERNC UIntPtr cxiGetKernelStackSize();
118
119EXTERNC int cxiInitVFS(int vfsType);
120#define cxiTermVFS()
121
122#else   /* not _KERNEL */
123
124#include <unistd.h>
125
126#ifndef NPTL
127
128#define cxiGetTid() ((cxiThreadId)getpid())
129/* Ensure that user cxiGetThreadId generates an id that is disjoint from
130 * the kernel thread ids (current->pid) which range up to MAX_GPFS_KERNEL_TID.
131 * A mask is applied to the thread id to remove it from this range; the
132 * mask is chosen so that it is compatible with THREAD_OWNER_METHOD_THREADID
133 * and the use of the upper 2 bits for mutex operations.
134 */
135#define GPFS_PTID_MASK 0x20000000               /* pthread id/handle mask */
136#define cxiGetThreadId() ((cxiThreadId)(pthread_self() | GPFS_PTID_MASK))
137
138#else
139
140EXTERNC cxiThreadId kxGetThreadID();
141EXTERNC int kxGetTimeOfDay(cxiTimeStruc_t *tP);
142/* sys_gettid is defined in kernel, but sys call not implemented in glibc,
143   so use our own ioctl with kxGetThreadID */
144#define cxiGetTid() (kxGetThreadID())
145
146/* cxiGetThreadId returns kernel thread id */
147extern pthread_key_t pid_key;
148#define cxiGetThreadId() ((cxiThreadId)(PTR_TO_INT32(pthread_getspecific(pid_key))))
149#endif /* !NPTL */
150#endif  /* _KERNEL */
151
152#ifdef _KERNEL
153/* Convert a kernel stack address to the thread ID of the thread that uses
154   that stack */
155EXTERNC int cxiStackAddrToThreadId(char* stackP, cxiThreadId* tidP);
156/* Convert a kernel thread pointer to the corresponding thread ID */
157EXTERNC int cxiThreadPtrToThreadId(char* threadP, cxiThreadId* tidP);
158#endif  /* _KERNEL */
159
160#ifdef _KERNEL
161/* Transfer data from buffer(s) in user space to or from a buffer in the
162 *  kernel.
163 */
164EXTERNC int cxiUiomove(char* kBufP, unsigned long nBytes, Boolean toKernel,
165                       struct cxiUio_t* uioP);
166
167EXTERNC void * cxiGetFcntlOwner(eflock_t *flP);
168#define cxiSetEflockOwner(eflockP, flP) (eflockP->l_owner = cxiGetFcntlOwner(flP))
169#define FL_OFFSET_MAX (loff_t)(~0ULL>>1)
170#endif  /* _KERNEL */
171
172
173/* System priority operations */
174
175/* Define priority constants inherited from AIX;  priority can only be
176 * relatively adjusted in Linux and not set directly.
177 * AIX setpri priority numbers 0-99 (as recorded in the mmfs.cfg file)
178 * will be decremented by 60 (PUSER+20) to get to the setpriority range
179 * of -20 to 20. Linux setpriority will then bound anything outside that
180 * range to the edges of the range.
181 */
182#define PRI_SCHED    16
183#define PUSER        40
184
185#define cxiSetPri(pid, newpri) (setpriority(PRIO_PGRP, (int)pid, \
186                                            (int)newpri-(PUSER+20)))
187#define cxiGetPri(pid) ((PUSER+20) + getpriority(PRIO_PGRP, (int)pid))
188
189/* Threads are actually a cloned process with separate signal masks */
190#define cxiSigThreadMask(a,b,c)  sigprocmask((a),(b),(c));
191
192#ifndef _KERNEL
193/* Assertion functions */
194#include <assert.h>
195#define cxiAssertFailed(STRING,FILE,LINE) \
196          __assert_fail((STRING),(FILE),(LINE),__ASSERT_FUNCTION)
197#endif
198
199void dump_trace_back(char *failingExpr, char *srcFileName, int srcLineNumber);
200
201#ifdef INSTRUMENT_LOCKS
202/* Statistics kept per lock class: number of lock acquisitions and the
203   number of times the lock appeared to be held before it was requested */
204struct BlockingMutexStats
205{
206  UInt32 bmsAcquires;                   /* number of times lock obtained */
207  UInt32 bmsConflicts;                  /* number of lock conflicts */
208};
209
210#define MAX_GPFS_LOCK_NAMES 48
211
212#ifdef _KERNEL
213EXTERNC struct BlockingMutexStats BlockingMutexStatsTable[MAX_GPFS_LOCK_NAMES];
214EXTERNC void InitBlockingMutexStats();
215#endif
216#endif  /* INSTRUMENT_LOCKS */
217
218
219
220#ifdef _KERNEL
221/* String functions for the kernel */
222static inline size_t cxiStrlen(const char *str1)
223{
224  const char *beg1;
225
226  if (str1 == NULL)
227    return 0;
228
229  for (beg1 = str1; *str1; str1++);
230
231  return str1 - beg1;
232}
233
234static inline char *cxiStrcpy(char *str1, const char *str2)
235{
236  char *beg1 = str1;
237
238  while (*str1++ = *str2++);
239
240  return beg1;
241}
242
243static inline char *cxiStrcat(char *str1, const char *str2)
244{
245  char *beg1;
246
247  for (beg1 = str1; *str1; str1++);
248
249  while (*str1++ = *str2++);
250
251  return beg1;
252}
253
254static inline int cxiStrcmp(const char *str1, const char *str2)
255{
256  /* This cannot have an ENTER macro because it is used to implement ENTER
257     processing */
258  for (; *str1 == *str2; str1++, str2++)
259    if (*str1 == '\0')
260      return 0;
261
262  return *str1 - *str2;
263}
264
265static inline char *cxiStrncpy(char *str1, const char *str2, size_t num)
266{
267  char *beg1 = str1;
268
269  while (num)
270  {
271    num--;
272    if ((*str1++ = *str2++) == '\0')
273      break;
274  }
275
276  /* strncpy is defined to null out the total length */
277  while (num)
278  {
279    num--;
280    *str1++ = '\0';
281  }
282
283  return beg1;
284}
285
286static inline char *cxiStrncat(char *str1, const char *str2, size_t num)
287{
288  char *beg1;
289
290  for (beg1 = str1; *str1; str1++);
291
292  while (num-- && (*str1 = *str2++))
293   str1++;
294
295  *str1 = '\0';
296
297  return beg1;
298}
299
300static inline char *cxiStrrchr(const char *str1, int ch)
301{
302  char *ret = NULL;
303
304  do
305  {
306    if (*str1 == (char)ch)
307      ret = (char *)str1;
308  }
309  while (*str1++);
310
311  return ret;
312}
313
314static inline char *cxiStrchr(const char *str1, int ch)
315{
316  char *ret = NULL;
317
318  do
319  {
320    if (*str1 == (char)ch)
321    {
322      ret = (char *)str1;
323      break;
324    }
325  }
326  while (*str1++);
327
328  return ret;
329}
330
331static inline int cxiMemcmp(const void *v1, const void *v2, size_t num)
332{
333  char *str1 = (char *)v1;
334  char *str2 = (char *)v2;
335
336  for (; num && (*str1 == *str2); str1++, str2++, num--);
337
338  if (num)
339    return *str1 - *str2;
340  else
341    return 0;
342}
343
344static inline void *cxiMemcpy(void *v1, const void *v2, size_t num)
345{
346  char *str1 = (char *)v1;
347  char *str2 = (char *)v2;
348
349  while (num--)
350    *str1++ = *str2++;
351
352  return v1;
353}
354
355static inline void *cxiMemset(void *v1, int c, size_t num)
356{
357  char *str1 = (char *)v1;
358
359  while (num--)
360    *str1++ = c;
361
362  return v1;
363}
364#endif  /* _KERNEL */
365
366/* Local file system list */
367#define FILESYSTEM_FILE "/etc/fstab"
368#define VI_FILE         "/bin/vi"
369#define ROOT_GROUP      "root"
370#define ROOT_USER       "root"
371
372/* AIX inherited constants from device.h */
373#define CFG_INIT 0x1
374#define CFG_TERM 0x2
375
376#ifdef _KERNEL
377/* AIX inherited constants from sleep.h */
378/* flags for e_thread_sleep */
379#define INTERRUPTIBLE           (1)     /* sleep is interruptible */
380#define LOCK_HANDLER            (2)     /* lock used by interrupt handlers */
381//#define LOCK_READ             (4)     /* complex lock read mode specified */
382#define LOCK_SIMPLE             (8)     /* simple lock specified */
383//#define LOCK_WRITE            (16)    /* complex lock write mode specified */
384/* return values from e_thread_block */
385#define THREAD_AWAKENED         (1)     /* normal wakeup value */
386#define THREAD_TIMED_OUT        (2)     /* sleep timed out */
387#define THREAD_INTERRUPTED      (4)     /* sleep interrupted by signal */
388#define THREAD_OTHER            (4096)  /* Beginning of subsystem values */
389#endif /* _KERNEL */
390
391
392/* --------------------------------------- */
393/* Interfaces usable only from kernel code */
394/* --------------------------------------- */
395
396#ifdef _KERNEL
397
398/* Macros to convert Linux kernel version to a decimal integer that can
399   be compared to the symbol LINUX_KERNEL_VERSION.
400   See the description of LINUX_KERNEL_VERSION in site.mcr.proto. */
401#define GPFS_KERNEL_VERSION(_major,_minor,_sub,_mod) \
402   ( (_major)*1000000 + (_minor)*10000 + (_sub)*100 + (_mod))
403
404/*
405 * Kernel memory allocation services:
406 *
407 * These are implemented as subroutines in gpl-linux/kxiSystem.C.  All
408 * allocations use storage class GFP_KERNEL.  There is no distinction
409 * between pinned and unpinned kernel memory in Linux, so the unpinned
410 * interfaces are defined in terms of the pinned interfaces as macros.
411 */
412EXTERNC void* cxiMallocPinned(int nBytes);
413#define cxiMallocUnpinned(nBytes)  cxiMallocPinned(nBytes)
414EXTERNC void cxiFreePinned(void* p);
415#define cxiFreeUnpinned(p)         cxiFreePinned(p)
416
417EXTERNC void *cxiBigMalloc(int size);
418EXTERNC void cxiBigFree(char *ptr);
419
420
421/* cxiIsSuperUser - return true if caller has maximum authorization (is root) */
422EXTERNC Boolean cxiIsSuperUser();
423
424/* cxiGetMaxFileSize - return the maximum file size the calling process
425 * is allowed to create.
426 */
427EXTERNC Int64 cxiGetMaxFileSize();
428
429/* NFS services for Linux */
430/* nfsd calls open and release for every file read/write.  Provide a way
431   to detect that nfsd is the caller and avoid the extra overhead. */
432EXTERNC Boolean cxiIsNFSThread();
433
434/* nfsd4 opens should not block waiting for conflicting oplocks to be
435 * broken.  They can accept EAGAIN and translate to NFS4ERR_DELAY as
436 * it does if it initiates a delegation recall.
437 */
438EXTERNC Boolean cxiIsNFS4Thread();
439
440EXTERNC Boolean cxiIsGPFSThread();
441
442EXTERNC Boolean cxiIsKswapdThread();
443
444EXTERNC Boolean cxiIsLockdThread();
445
446/* See if a cxiFlock_t belongs to NFS (lockd) */
447#define cxiGetLockCaller(lockP) ((lockP)->l_caller)
448#define cxiIsNFSLock(lockP)     ((lockP)->l_caller == L_CALLER_LOCKD)
449
450/* No-op services on linux */
451EXTERNC int socket_aio_dequeue();
452
453/* kupdate services for Linux */
454/* Use to identify syncs from kupdate that are generated way
455   too often by Linux (every 5 seconds). */
456EXTERNC Boolean cxiIsKupdateThread();
457
458#ifdef SMB_LOCKS
459/* Samba services for Linux */
460/* smbd calls open and subsequently makes calls to set open deny modes and
461   op locks.  Provide a way to distinguish these Samba calls from calls
462   from other users for which default actions on open and op locks must
463   be taken */
464EXTERNC Boolean cxiIsSambaOrLockdThread();
465
466/* Samba services for Linux */
467/* Provide a way to distinguish Samba calls from calls
468   from other users */
469EXTERNC Boolean cxiIsSambaThread();
470#endif
471
472/* The nfsd threads are allowed to FSYNC their writes. */
473#define cxiAllowNFSFsync() cxiIsNFSThread()
474
475/* OS dependent VFS calls */
476#define cxiDisconnectVfs(PVP)   /* nothing ??? */
477
478EXTERNC void cxiDeleteMmap(cxiVmid_t);  /* delete memory map */
479
480/* Set OS dependent virtual node type and device */
481EXTERNC void cxiSetOSNodeType(struct cxiNode_t *cnP, cxiMode_t mode,
482                              cxiDev_t rdev);
483#define cxiOSNodeTypeIs(CNP,VTYPE) (((CNP)->nType) == (VTYPE))
484
485EXTERNC Boolean cxiCanUncacheOSNode(void *osVfsP, struct cxiNode_t *cnP, void **vPP);
486
487#ifdef __cplusplus
488#ifdef CCL
489EXTERNC void *cxiAddOSNode(void *dentryP, void *vP, DentryOpTableTypes dopTabType, int lookup = 0);
490#else
491EXTERNC void *cxiAddOSNode(void *dentryP, void *vP, int lookup = 0);
492#endif
493#endif
494
495/* Kernel operations to copy data between user and kernel space */
496EXTERNC int cxiCopyIn(char *from, char *to, unsigned long size);
497EXTERNC int cxiCopyOut(char *from, char *to, unsigned long size);
498EXTERNC int cxiCopyInstr(char *from, char *to, unsigned long size,
499                         unsigned long *len);
500
501EXTERNC long cxiSafeGetLong(long* from);
502EXTERNC void cxiSafePutLong(long val, long* to);
503EXTERNC int cxiSafeGetInt(int* from);
504EXTERNC void cxiSafePutInt(int val, int* to);
505
506/* Adhere to XPG 1170 behaviour */
507#define cxiIsXPG()  1
508
509/* Routine to send a signal to the current thread/process */
510EXTERNC void cxiSendSigThread(int sig);
511
512/* Routines to manipulate cxiWaitEvent_t objects. */
513EXTERNC void cxiWaitEventInit(cxiWaitEvent_t* weP);
514EXTERNC Boolean cxiWaitEventHasWaiters(cxiWaitEvent_t* weP);
515
516/* Kernel-only synchronization primitives.  A cxiBlockingMutex_t can be used
517   to protect a critical section.  Requests to acquire a cxiBlockingMutex
518   that is already held by another thread will block the caller.  Must
519   initialize the mutex before acquiring it, and must terminate it before
520   deallocating the storage it occupies.  Implemented using semaphores on
521   Linux. */
522EXTERNC void cxiBlockingMutexInit(cxiBlockingMutex_t* mP, int bmNameIdx);
523EXTERNC void cxiBlockingMutexAcquire(cxiBlockingMutex_t* mP) REGPARMS;
524EXTERNC void cxiBlockingMutexRelease(cxiBlockingMutex_t* mP) REGPARMS;
525EXTERNC void cxiBlockingMutexTerm(cxiBlockingMutex_t* mP);
526EXTERNC Boolean cxiBlockingMutexHeldByCaller(cxiBlockingMutex_t* mP);
527EXTERNC Boolean cxiBlockingMutexHasWaiters(cxiBlockingMutex_t* mP);
528
529/* Yield the CPU to allow other processes to run */
530EXTERNC void cxiYield();
531
532/* Well defined portability interface calling changing (depending on kernel
533 * level) linux interface
534 */
535EXTERNC int cxiFillDir(void *argP, const char *nameP, 
536                       int namelen, offset_t offset, ino_t ino);
537
538/* A cxiWaitEvent_t can be used like a condition variable using the calls
539   below.  There must be an associated cxiBlockingMutex_t held when calling
540   cxiWaitEventWait that will be reacquired before returning.  The routine
541   cxiWaitEventSignal wakes up one thread waiting in cxiWaitEventWait,
542   while cxiWaitEventBroadcast wakes all such waiting threads.  The
543   cxiWaitEventWakeupOne routine is the same as cxiWaitEventSignal except
544   that multiple calls will each pick a different thread.  The flags
545   parameter to cxiWaitEventWait indicates whether or not the wait can be
546   interrupted by a signal.  It should be set to INTERRUPTIBLE if
547   interrupts due to signals are desired, otherwise set to 0. */
548EXTERNC int cxiWaitEventWait(cxiWaitEvent_t* weP, cxiBlockingMutex_t* mutexP,
549                             int waitFlags);
550EXTERNC void cxiWaitEventSignal(cxiWaitEvent_t* weP);
551EXTERNC void cxiWaitEventWakeupOne(cxiWaitEvent_t* weP);
552EXTERNC void cxiWaitEventBroadcast(cxiWaitEvent_t* weP);
553EXTERNC void cxiWaitEventBroadcastRC(cxiWaitEvent_t* weP, int rc);
554
555/* Kill the system due to a fatal error */
556EXTERNC void cxiPanic(const char* panicStrP);
557
558/* Get the address of the first byte not addressible by processes */
559EXTERNC UIntPtr cxiGetKernelBoundary();
560
561/* Return true if this process holds the big kernel lock (BKL) */
562EXTERNC Boolean cxiHoldsBKL();
563
564EXTERNC void cxiExportModuleStruct(void *modAddr);
565EXTERNC void cxiIncModuleCounter(int up);
566
567EXTERNC void cxiSetBit(unsigned long *flagP, int flag_bit);
568EXTERNC void cxiClearBit(unsigned long *flagP, int flag_bit);
569EXTERNC Boolean cxiTestBit(unsigned long *flagP, int  flag_bit);
570
571/* Tell OS if a thread is involved in handling VM page-out requests */
572EXTERNC Boolean cxiSetPageoutThread();
573EXTERNC void cxiClearPageoutThread();
574
575#ifdef API_32BIT
576#ifdef GPFS_ARCH_IA64
577/* Macros for 32-bit API support. 32-bit addresses are in region 0,
578   so the upper 32-bits of 32-bit proc addresses are just zero extended. */
579#define MASK_UPPER32 0xFFFFFFFF00000000UL
580#define cxiIS64U(addr) ((((UIntPtr)addr) & MASK_UPPER32) != 0)
581#endif /* GPFS_ARCH_IA64 */
582#ifdef GPFS_ARCH_X86_64
583/* Need to define cxiIS64U in portability layer for Opteron. */
584EXTERNC int cxiIS64U(char *addr);
585#endif /* GPFS_ARCH_X86_64 */
586#endif /* API_32BIT */
587
588#endif  /* _KERNEL */
589
590/* Return current time of day in seconds and nanoseconds. */
591#ifdef _KERNEL
592EXTERNC int cxiGetTOD(cxiTimeStruc_t *tP);
593
594static inline void cxiInvalidateAttr(cxiNode_t *cnP, int what)
595{
596  cnP->icValid &= ~what;
597  if (what & CXI_IC_PERM)
598    cxiInvalidatePerm(cnP);
599}
600
601#else /* !_KERNEL */
602
603struct timezone;
604EXTERNC int gettimeofday __P ((struct timeval *__tv, struct timezone *__tz));
605/* cxiTimeStruc_t should have same size as linux struct timeval.
606 * Call LGPL library function and translate microseconds from call
607 * to nanoseconds.
608 */
609
610EXTERNC inline int cxiGetTOD(cxiTimeStruc_t *tP)
611{
612#ifdef STANDALONE_PROGRAM
613   int rc = gettimeofday((struct timeval *)tP, NULL);
614   tP->tv_nsec = tP->tv_nsec * 1000;
615   return rc;
616#else
617  return kxGetTimeOfDay(tP);
618#endif
619
620#define cxiSafeGetLong(_ptr) (*_ptr)
621#define cxiSafeGetInt(_ptr) (*_ptr)
622}
623
624/* String functions in user space */
625#define cxiStrcpy  strcpy
626#define cxiStrncpy strncpy
627#define cxiStrcat  strcat
628#define cxiStrncat strncat
629#define cxiStrrchr strrchr
630#define cxiStrchr  strchr
631#define cxiStrcmp  strcmp
632#define cxiMemcpy  memcpy
633#define cxiStrlen  strlen
634#define cxiMemcmp  memcmp
635#define cxiMemset  memset
636
637#endif /* _KERNEL */
638
639/* Samba share/delegate flags.  Unlike NFSV4, the interface here is
640 * just between our Samba vfs library and ourselves so we can define
641 * these to be any values we choose.  */
642#define CXI_ACCESS_READ   1
643#define CXI_ACCESS_WRITE  2
644#define CXI_ACCESS_BOTH   3
645#define CXI_DENY_NONE     0
646#define CXI_DENY_READ     1
647#define CXI_DENY_WRITE    2
648#define CXI_DENY_BOTH     3
649#define CXI_DELEGATE_NONE  0
650#define CXI_DELEGATE_READ  1
651#define CXI_DELEGATE_WRITE 2
652
653/* Whatever the values specified in Samba for share, deny, and oplock flags,
654 * we have to translate them to our SMB open and oplock flags.
655 * Define macros to translate and error check.
656 */
657#define XLATE_SAMBA_ACCESS(SAMBA_SHARE, SHARE) \
658  if (SAMBA_SHARE == CXI_ACCESS_READ) SHARE |= coRead; \
659  else if (SAMBA_SHARE == CXI_ACCESS_WRITE) SHARE |= coWriteM|coWriteA; \
660  else if (SAMBA_SHARE == CXI_ACCESS_BOTH) SHARE |= coRead|coWriteM|coWriteA; \
661  else if (SAMBA_SHARE != 0) goto xerror;
662
663#define XLATE_SAMBA_DENY(SAMBA_DENY, SHARE) \
664  if (SAMBA_DENY == CXI_DENY_NONE) SHARE &= ~coDenyAll; \
665  else if (SAMBA_DENY == CXI_DENY_READ) SHARE |= coDenyR; \
666  else if (SAMBA_DENY == CXI_DENY_WRITE) SHARE |= coDenyWM|coDenyWA; \
667  else if (SAMBA_DENY == CXI_DENY_BOTH) SHARE |= coDenyR|coDenyWM|coDenyWA; \
668  else goto xerror;
669
670#define XLATE_SAMBA_DELEGATE(SAMBA_DELEGATE, OPLOCK) \
671  if (SAMBA_DELEGATE == CXI_DELEGATE_NONE) OPLOCK |= smbOplockNone; \
672  else if (SAMBA_DELEGATE == CXI_DELEGATE_READ) OPLOCK |= smbOplockShared; \
673  else if (SAMBA_DELEGATE == CXI_DELEGATE_WRITE) OPLOCK |= smbOplockExclusive; \
674  else goto xerror;
675
676/* Call Linux-specific F_SETLEASE operation.
677   This will register the caller so that it will be notified via SIGIO
678   when an OpLock break is required (REVOKE_LEASE is called).
679*/
680#define CXI_REGISTER_LEASE(FD, LTYPE) \
681  fcntl(FD, F_SETLEASE, (LTYPE == CXI_DELEGATE_READ )? F_RDLCK: \
682                        (LTYPE == CXI_DELEGATE_WRITE)? F_WRLCK: F_UNLCK)
683
684/* Call Linux-specific F_GETLEASE */
685#define CXI_GET_LEASE_HELD(FD, LEASE) \
686  LEASE = fcntl(FD, F_GETLEASE, 0); \
687  LEASE = (LEASE == F_RDLCK)? CXI_DELEGATE_READ: \
688          (LEASE == F_WRLCK)? CXI_DELEGATE_WRITE: \
689          (LEASE == F_UNLCK)? CXI_DELEGATE_NONE: LEASE
690
691#if defined(NFS4_CLUSTER) || defined(NFS4_VCM)
692
693#define OPEN4_SHARE_ACCESS_READ  0x00000001
694#define OPEN4_SHARE_ACCESS_WRITE 0x00000002
695#define OPEN4_SHARE_ACCESS_BOTH  0x00000003
696#define OPEN4_SHARE_DENY_NONE    0x00000000
697#define OPEN4_SHARE_DENY_READ    0x00000010
698#define OPEN4_SHARE_DENY_WRITE   0x00000020
699#define OPEN4_SHARE_DENY_BOTH    0x00000030
700#define OPEN_DELEGATE_NONE       0x00000000
701#define OPEN_DELEGATE_READ       0x00000100
702#define OPEN_DELEGATE_WRITE      0x00000200
703
704#define CXI_SHARE_ACCESS_READ   OPEN4_SHARE_ACCESS_READ
705#define CXI_SHARE_ACCESS_WRITE  OPEN4_SHARE_ACCESS_WRITE
706#define CXI_SHARE_ACCESS_BOTH   OPEN4_SHARE_ACCESS_BOTH
707#define CXI_SHARE_DENY_NONE     OPEN4_SHARE_DENY_NONE
708#define CXI_SHARE_DENY_READ     OPEN4_SHARE_DENY_READ
709#define CXI_SHARE_DENY_WRITE    OPEN4_SHARE_DENY_WRITE
710#define CXI_SHARE_DENY_BOTH     OPEN4_SHARE_DENY_BOTH
711#define CXI_OPEN_DELEGATE_NONE  OPEN_DELEGATE_NONE
712#define CXI_OPEN_DELEGATE_READ  OPEN_DELEGATE_READ
713#define CXI_OPEN_DELEGATE_WRITE OPEN_DELEGATE_WRITE
714
715/* Whatever the values specified in the NFS4 interface for share, deny, and
716 * delegate flags, we have to translate them to our SMB open and oplock flags.
717 * Define macros to translate and error check.
718 */
719#define XLATE_NFS4_ACCESS(NFS4_SHARE, SHARE) \
720  if (NFS4_SHARE == CXI_SHARE_ACCESS_READ) SHARE |= coRead; \
721  else if (NFS4_SHARE == CXI_SHARE_ACCESS_WRITE) SHARE |= coWriteM|coWriteA; \
722  else if (NFS4_SHARE == CXI_SHARE_ACCESS_BOTH) SHARE |= coRead|coWriteM|coWriteA; \
723  else if (NFS4_SHARE != 0) goto xerror;
724
725#define XLATE_NFS4_DENY(NFS4_DENY, SHARE) \
726  if (NFS4_DENY == CXI_SHARE_DENY_NONE) SHARE &= ~coDenyAll; \
727  else if (NFS4_DENY == CXI_SHARE_DENY_READ) SHARE |= coDenyR; \
728  else if (NFS4_DENY == CXI_SHARE_DENY_WRITE) SHARE |= coDenyWM|coDenyWA; \
729  else if (NFS4_DENY == CXI_SHARE_DENY_BOTH) SHARE |= coDenyR|coDenyWM|coDenyWA; \
730  else goto xerror;
731
732#define XLATE_NFS4_DELEGATE(NFS4_DELEGATE, OPLOCK) \
733  if (NFS4_DELEGATE == CXI_OPEN_DELEGATE_NONE) OPLOCK |= smbOplockNone; \
734  else if (NFS4_DELEGATE == CXI_OPEN_DELEGATE_READ) OPLOCK |= smbOplockShared; \
735  else if (NFS4_DELEGATE == CXI_OPEN_DELEGATE_WRITE) OPLOCK |= smbOplockExclusive; \
736  else goto xerror;
737
738#endif /* NFS4_CLUSTER */
739
740#ifdef NFS4_VCM
741/* VCM definitions */
742#define boolean_t Boolean
743#define uint16_t UInt16
744
745typedef void * vcm_peerHandle_t;
746typedef uint16_t vcm_opRights_t;
747typedef UInt64 vcm_revokeTag_t;
748
749/* VCM flags */
750
751/* Flags for vcm_peerRegister() */
752#define VCM_PRGY_RTN_OPENS    0x00000001
753#define VCM_PRGY_ENF_VREG     0x00000002
754#define VCM_PRGY_ENF_VDIR     0x00000004
755#define VCM_PRGY_ENF_VLNK     0x00000008
756
757/* Flags for vcm_peerRevoke() */
758#define VCM_P_RVK_NOWAIT      0x00000001
759#define VCM_P_RVK_FORCE       0x00000002
760
761/* Flags for getOpRights */
762#define VCM_P_GR_NOWAIT       0x00000001
763
764/* Flags for returnOpRights */
765#define VCM_P_RR_REL_OBJ      0x00000001
766
767/* Flags for vcm_peerCreateReq_t */
768#define VCM_P_CREQ_F_CREATE   0x00000001
769
770
771/* GPFS peer-side utilities */
772#define cxiPeerUnregister() (NOOP);
773#define cxiGetPeerTag() ((uint64_t)NULL)
774#define cxiGetPeerHandle() ((vcm_peerHandle_t)NULL)
775#define cxiWatchVCM(nfsP, doClose) (0);
776#define cxiCleanupVCM(nfsP) (0);
777#define cxiFSCleanupVCM(privVfsP) (0);
778
779#define cxiInitVCM(nfsP) \
780{ \
781  nfsP->vcmRights = 0; \
782  nfsP->vcmRevokeRights = 0; \
783  nfsP->vcmRevokeTag = 0; \
784}
785
786/* GPFS peer-side interfaces */
787#define gpfs_vcm_releaseObjHandle(peerTag, objHandleP) (0)
788#define delegateInternal(vP, vinfoP, acc, flags, cb_rtn, cookie) (0)
789
790/* VCM-side interfaces */
791#define vcm_peerRegister(peerInfoP, peerHandleP) (0)
792#define vcm_peerUnregister(peerHandle) (0)
793#define vcm_peerRevoke(peerHandle, objHandle, peerOpHandle, peerTag, \
794                       rights, flags, releObjHandleP) (0)
795#define vcm_peerTest(tc, fid, vfsP, opInfoP) (0)
796
797/* The CXI_OPEN/SHARE values will be set to the VCM Rights
798 * Here some useful comparison macros based on these defines are included. */
799#define CXI_DELEGATE          (CXI_OPEN_DELEGATE_READ | CXI_OPEN_DELEGATE_WRITE)
800#define CXI_SHARE_ALLOW       (CXI_SHARE_ACCESS_READ | CXI_SHARE_ACCESS_WRITE)
801#define CXI_SHARE_DENY        (CXI_SHARE_DENY_READ | CXI_SHARE_DENY_WRITE)
802#define CXI_SHARE             (CXI_SHARE_ALLOW | CXI_SHARE_DENY)
803
804#define CXI_IS_DELEGATE_READ(R)  (0 != (R & CXI_OPEN_DELEGATE_READ))
805#define CXI_IS_DELEGATE_WRITE(R) (0 != (R & CXI_OPEN_DELEGATE_WRITE))
806#define CXI_IS_SHARE_READ(R)     (0 != (R & CXI_SHARE_ACCESS_READ))
807#define CXI_IS_SHARE_WRITE(R)    (0 != (R & CXI_SHARE_ACCESS_WRITE))
808#define CXI_IS_DENY_READ(R)      (0 != (R & CXI_SHARE_DENY_READ))
809#define CXI_IS_DENY_WRITE(R)     (0 != (R & CXI_SHARE_DENY_WRITE))
810#define CXI_IS_DELEGATE(R)       (0 != (R & CXI_DELEGATE))
811#define CXI_IS_SHARE_ALLOW(R)    (0 != (R & CXI_SHARE_ALLOW))
812#define CXI_IS_SHARE_DENY(R)     (0 != (R & CXI_SHARE_DENY))
813#define CXI_IS_SHARE(R)          (0 != (R & CXI_SHARE))
814
815#endif /* NFS4_VCM */
816
817#if defined(DMAPI) || defined(SANERGY)
818
819EXTERNC int cxiPathToVfsP(void **privVfsPP, char *pathname, void **ndPP, void **gP, Boolean traverseLink);
820EXTERNC void cxiPathRel(void * ndP);
821EXTERNC void cxiSetCred(void *eCredP);
822
823#endif /* DMAPI or SANERGY */
824
825#ifdef UIDREMAP
826EXTERNC size_t cxiGetUserEnvironmentSize(void);
827EXTERNC int cxiGetUserEnvironment(char* buf, size_t len);
828#endif
829
830EXTERNC Boolean cxiHasMountHelper();
831
832EXTERNC int cxiCheckThreadState(cxiThreadId tid);
833
834#ifdef P_NFS4
835EXTERNC int cxiSetFH(int *fhP, int sid);
836EXTERNC int cxiOpenState(void *vfsP, void *p);
837EXTERNC int cxiChangeState(void *vfsP, void *p);
838EXTERNC int cxiRecallLayout(void *vfsP, void *vP, void *p);
839EXTERNC int cxiGetDeviceList(int nDests, int *dests, void *p);
840EXTERNC int cxiGetDeviceInfo(void *p);
841EXTERNC int cxiGetLayout(int nDests, int *dests, cxiVattr_t *vattr,
842                         int myAddr, void *p);
843#endif
844#endif  /* _h_cxiSystem_plat */
845
846
Note: See TracBrowser for help on using the repository browser.