source: gpfs_3.1_ker2.6.20/lpp/mmfs/src/gpl-linux/tscalls.c @ 214

Last change on this file since 214 was 16, checked in by rock, 17 years ago
File size: 9.1 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/* @(#)78       1.2  src/avs/fs/mmfs/ts/kernext/gpl-linux/tscalls.c, mmfs, avs_rgpfs24, rgpfs24s007a 10/27/06 16:48:13 */
34/*
35 * Portability layer equivalent of ts/util/tscalls.c
36 * Includes a subset of the libgpfs interfaces that GPFS has provided
37 * in open-source form.
38 *
39 * Contents:
40 *   gpfs_getacl
41 *   gpfs_putacl
42 *   gpfs_set_share
43 *   gpfs_set_lease
44 *   gpfs_get_lease
45 */
46
47#include <stdlib.h>
48#include <sys/errno.h>
49#include <sys/ioctl.h>
50
51#include <fcntl.h>
52#define F_SETLEASE 1024
53#define F_GETLEASE 1025
54
55#include <cxiSystem.h>
56#include <gpfs_gpl.h> /* open-source segment of gpfs.h */
57#include <cxiTSFattr.h>
58
59#define  IOCTL_FATTR   53
60#define  IOCTL_GETACL  56
61#define  IOCTL_PUTACL  57
62#define  IOCTL_SHARE  112
63#define  IOCTL_LEASE  113
64
65struct ioArgs
66{
67  long arg1;
68  long arg2;
69  long arg3;
70  long arg4;
71  long arg5;
72};
73
74/*-------------------------------------------------------------------------
75 * NAME:        gpfs_getacl
76 *
77 * FUNCTION:    Interface to read GPFS ACLs
78 *
79 * Returns:      0      Successful
80 *              -1      Failure
81 *
82 * Errno:       ENOSYS  function not available
83 *-------------------------------------------------------------------------*/
84int
85gpfs_getacl(char *pathname,
86            int   flags,
87            void *aclP)
88{
89  int rc;
90  int fd;
91  struct ioArgs io;
92
93  fd = open(GPFS_DEVNAME, O_RDONLY);
94  if (fd < 0)
95  {
96    rc = -1;
97    errno = ENOSYS;
98    goto xerror;
99  }
100
101  /* Retrieve the ACL from GPFS */
102  io.arg1 = (long)pathname;
103  io.arg2 = (long)flags;
104  io.arg3 = (long)aclP;
105
106  rc = ioctl(fd, IOCTL_GETACL, &io);
107
108xerror:
109  if (fd >= 0)
110    close(fd);
111
112  return rc;
113}
114
115
116/*-------------------------------------------------------------------------
117 * NAME:        gpfs_putacl
118 *
119 * FUNCTION:    Interface to store GPFS ACLs
120 *
121 * Returns:      0      Successful
122 *              -1      Failure
123 *
124 * Errno:       ENOSYS  function not available
125 *-------------------------------------------------------------------------*/
126int
127gpfs_putacl(char *pathname,
128            int   flags,
129            void *aclP)
130{
131  int rc;
132  int fd;
133  struct ioArgs io;
134
135  fd = open(GPFS_DEVNAME, O_RDONLY);
136  if (fd < 0)
137  {
138    rc = -1;
139    errno = ENOSYS;
140    goto xerror;
141  }
142
143  /* Store the ACL into GPFS */
144  io.arg1 = (long)pathname;
145  io.arg2 = (long)flags;
146  io.arg3 = (long)aclP;
147
148  rc = ioctl(fd, IOCTL_PUTACL, &io);
149
150xerror:
151  if (fd >= 0)
152    close(fd);
153
154  return rc;
155}
156
157
158/*-------------------------------------------------------------------------
159 * NAME:        gpfs_set_share
160 *
161 * FUNCTION:    Samba interface to GPFS OpenLks
162 *              Called from the Samba daemon to reserve a share
163 *
164 * INPUT:       object_fd : file descriptor of the object to share
165 *              share: modes being requested
166 *              deny : modes to deny
167 * OUTPUT:      None
168 *
169 * Returns:      0      Successful
170 *              -1      Failure
171 * Errno:       ENOENT  File not found
172 *              EACCES  Share mode not granted
173 *-------------------------------------------------------------------------*/
174int gpfs_set_share(int object_fd,
175                   unsigned int share,
176                   unsigned int deny)
177{
178  int rc;
179  int fd;
180  struct ioArgs io;
181
182  fd = open(GPFS_DEVNAME, O_RDONLY);
183  if (fd < 0)
184  {
185    rc = -1;
186    errno = ENOSYS;
187    goto xerror;
188  }
189
190  /* Request the share from GPFS */
191  io.arg1 = (long)object_fd;
192  io.arg2 = (long)share;
193  io.arg3 = (long)deny;
194
195  rc = ioctl(fd, IOCTL_SHARE, &io);
196
197xerror:
198  if (fd >= 0)
199    close(fd);
200
201  return rc;
202}
203
204/*-------------------------------------------------------------------------
205 * NAME:        gpfs_set_lease
206 *
207 * FUNCTION:    Samba interface to GPFS OpLks
208 *              Called from the Samba daemon to obtain a lease
209 *
210 * INPUT:       object_fd : file descriptor of the object to lease
211 *              leaseType: mode being requested
212 * OUTPUT:      None
213 *
214 * Returns:      0      Successful
215 *              -1      Failure
216 * Errno:       EACCES  Lease not granted
217 *              ENOENT  File not found
218 *-------------------------------------------------------------------------*/
219int gpfs_set_lease(int object_fd,
220                   unsigned int leaseType)
221{
222  int rc = 0;
223  int fd;
224  int lrc, serrno;
225  struct ioArgs io;
226
227  fd = open(GPFS_DEVNAME, O_RDONLY);
228  if (fd < 0)
229  {
230    rc = -1;
231    errno = ENOSYS;
232    goto xerror;
233  }
234
235  /* Queue Linux structures required for break notification */
236  rc = CXI_REGISTER_LEASE(object_fd, leaseType);
237  if (rc)
238    return rc;
239
240  /* Request the lease from GPFS */
241  io.arg1 = (long)object_fd;
242  io.arg2 = (long)leaseType;
243  io.arg3 = (long)NULL;
244  io.arg4 = (long)NULL;
245
246  rc = ioctl(fd, IOCTL_LEASE, &io);
247
248  if (rc && (leaseType != GPFS_LEASE_NONE))
249  {
250    serrno = errno;
251
252    /* Dequeue Linux structures */
253    lrc = CXI_REGISTER_LEASE(object_fd, GPFS_LEASE_NONE);
254
255    errno = serrno;
256  }
257
258xerror:
259  if (fd >= 0)
260    close(fd);
261
262  return rc;
263}
264
265
266/*-------------------------------------------------------------------------
267 * NAME:        gpfs_get_lease
268 *
269 * FUNCTION:    Samba interface to GPFS OpLks
270 *              Called from the Samba daemon to query leases held
271 *
272 * INPUT:       object_fd : file descriptor of the leased object
273 * OUTPUT:      None
274 *
275 * Returns:     GPFS_LEASE_READ
276 *              GPFS_LEASE_WRITE
277 *              GPFS_LEASE_NONE
278 *              -1      Failure
279 *
280 * Errno:       ENOENT  File not found
281 *              EINVAL
282 *-------------------------------------------------------------------------*/
283int gpfs_get_lease(int object_fd)
284{
285  int rc = 0;
286
287  CXI_GET_LEASE_HELD(object_fd, rc);
288
289  if (rc<0)
290  {
291    errno = -rc;
292    rc = -1;
293  }
294  return rc;
295}
296
297/*-------------------------------------------------------------------------
298 * NAME:        gpfs_prealloc()
299 *              Preallocate disk storage for the file handle that has
300 *              already been opened for writing, starting at the specified
301 *              starting offset and covering at least the number of bytes
302 *              requested. Allocations are rounded to block boundaries
303 *              (block size can be found using fstat() in st_blksize.)
304 *              Any existing data already in the file will not be modified.
305 *              Any read of the preallocated blocks will return zeros.
306 *
307 * FUNCTION:
308 * Returns:      0      Successful
309 *              -1      Failure
310 *
311 * Errno:       ENOSYS  No prealloc service available
312 *              EBADF   Bad file handle
313 *              EINVAL  Not a GPFS file
314 *              EINVAL  Not a regular file
315 *              EINVAL  StartOffset or BytesToPrealloc < 0
316 *              EACCES  File not opened for writing
317 *              EDQUOT  Quota exceeded
318 *              ENOSPC  Not enough space on disk
319 *-------------------------------------------------------------------------*/
320int
321gpfs_prealloc(int FileHandle, gpfs_off64_t StartOffset,
322                              gpfs_off64_t BytesToTransfer)
323{
324  int rc;
325  int fd;
326  struct ioArgs io;
327  struct filePreallocation preAlloc = {0,0,0};
328
329  fd = open(GPFS_DEVNAME, O_RDONLY);
330  if (fd < 0)
331  {
332    rc = -1;
333    errno = ENOSYS;
334    goto xerror;
335  }
336
337  /* Construct the filePreallocation structure */
338  preAlloc.size = BytesToTransfer;
339  preAlloc.offset = StartOffset;
340  preAlloc.flags = 0;
341
342  /* Store the ACL into GPFS */
343  io.arg1 = (long)FileHandle;
344  io.arg2 = (long)PREALLOCATE_FILE;
345  io.arg3 = (long)&preAlloc;
346  io.arg4 = (long)NULL;
347
348  rc = ioctl(fd, IOCTL_FATTR, &io);
349
350xerror:
351  if (fd >= 0)
352    close(fd);
353
354  return rc;
355}   /* --------- end of gpfs_prealloc() -------------- */
356
357
Note: See TracBrowser for help on using the repository browser.