Hi Brad,
Thanks for the link! You just saved me a list search!
On Tue, 29 Nov 2005, Bradley W Settlemyer wrote:
> This is the native lib stuff I did to learn about PVFS2.
>
> The code comes with unit tests -- though I've looked at the code so
> infrequently since early 2004 that I cannot really be sure what its
> limitations are anymore.
>
> For example, I never concerned myself with making the code re-entrant.
> I doubt that the open and close functions are threadsafe. The stateless
> functions like read and write are probably fine in most contexts.
>
> Now, why fork wouldn't work is a mystery to me. Though forking an open
> file descriptor may lead to failures at close time (I would have to read
> the code to be sure). Either way, I never tested it, so no assurances.
Hmm.. Didn't Hamza say that the code works with fork? :)
> > Another thing I tried is to use fork() instead of pthreads. The pseudo
> > code is as follows:
> >
> > main:
> > for 1 to n
> > {
> > fork ();
> > child {
> > PVFS_util_init_defaults ();
> > thread_func ();
> > PVFS_sys_finalize ();
> > }
> > }
> > parent {
> > waitforchilds;
> > }
> >
> > thread_func:
> > filesize=1GB
> > offset= rand (0 - 1GB)
> > for i to m
> > {
> > PVFS_sys_read (100KB, offset);
> > }
> >
> > this code works correctly.
Thanks,
Murali
>
> The code and tests are available at:
> http://www.parl.clemson.edu/~bradles/downloads/pvfs2-native-lib-0.0.3.tar.gz
>
> Cheers,
> Brad
>
>
> Hamza Kaya wrote:
> > Hi Murali,
> >
> > I found these functions from a previous post in this mail list [pvfs2
> > native api]. I will attach the code too. As you guess they use the
> > system interface to handle file operations.
> >
> > I used the unix calls (fopen etc.) instead of the pvfs_* calls. It works
> > correctly.
> >
> > When I used fork and unix calls I got approximately 3 thread_func calls
> > per second. However with fork and system interface I got approx. 400
> > thread_func calls per second. What may cause this difference? In the
> > first case I observed that the client machine and the server machine
> > contacts with the same port number. In other words client use the same
> > port number to connect the servers 3334th port. In the second case this
> > port number changed. I observed many different port numbers connecting
> > to pvfs2 servers port. [Raw sockets used to listen the network] May be
> > the reason is this.
> >
> > On 11/29/05, *Murali Vilayannur* <[EMAIL PROTECTED]
> > <mailto:[EMAIL PROTECTED]>> wrote:
> >
> > Hi Hamza,
> >
> > > thread_func:
> > > filesize=1GB
> > > offset= rand (0 - 1GB)
> > > pvfs_open ("/pvfs2/1GBfile");
> > > for i to m
> > > {
> > > pvfs_lseek (offset);
> > > pvfs_read (100K);
> > > }
> >
> > What do the functions pvfs_open, pvfs_lseek and pvfs_read do? It
> > would be
> > good to see the code or pseudo-code for those as well (just in case
> > there is something wrong there).
> > I presume that they somehow make use of the pvfs2 system interface to
> > offer the above functionality.
> >
> >
> > > When I executed the programme with n=1 it works correctly. However
> > > when n>1 I got the error:
> > > ===================================
> > > [14:50:19.904834] critical BMI failure (null callback)
> > > th: src/io/flow/flowproto-bmi-trove/flowproto-multiqueue.c:1701:
> > > bmi_to_mem_callback_fn: Assertion `q_item->parent->state !=
> > > FLOW_COMPLETE' failed.
> > > Aborted
> > > ===================================
> > > What may be the problem?
> >
> > Could you trigger this thru the VFS as well?
> > Or only thru the system interface?
> > Thanks for the reports
> > Murali
> > >
> > > Thanks very much.
> > >
> > > --
> > > hamza
> > >
> > > _______________________________________________
> > > PVFS2-users mailing list
> > > [email protected]
> > <mailto:[email protected]>
> > > http://www.beowulf-underground.org/mailman/listinfo/pvfs2-users
> > >
> > >
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > /*
> > * (C) 2004 Clemson University
> > *
> > * See COPYING in top-level directory.
> > */
> >
> > #include <errno.h>
> > #include <fcntl.h>
> > #include <limits.h>
> > #include <stdarg.h>
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <string.h>
> > #include <sys/resource.h>
> > #include <sys/stat.h>
> > #include <time.h>
> > #include <unistd.h>
> > #include "pvfs2.h"
> > #include "pvfs2-request.h"
> > #include "pvfs2-native.h"
> >
> > /* Define success and error return values */
> > #define PVFS_FD_SUCCESS 0
> > #define PVFS_FD_FAILURE -1
> >
> > /* Define GNU's O_NOFOLLOW flag to be false if its not set */
> > #ifndef O_NOFOLLOW
> > #define O_NOFOLLOW 0
> > #endif
> >
> > /* Define a max macro */
> > #define max(x, y) (((x) > (y)) ? (x) : (y))
> >
> > /* PVFS Descriptor table entry */
> > typedef struct pvfs_descriptor_s
> > {
> > int id;
> > PVFS_fs_id fs_id;
> > PVFS_handle pvfs_handle;
> > int flags;
> > off64_t offset;
> > int is_in_use;
> > } pvfs_descriptor;
> >
> > /* PVFS File Descriptor Offset */
> > static rlim_t pvfs_fd_offset = 0;
> >
> > /* PVFS System initialization indicator */
> > static int pvfs_is_sys_initialized = 0;
> >
> > /* PVFS Descriptor table */
> > static pvfs_descriptor *descriptor_table = 0;
> >
> > /* PVFS Descriptor table size */
> > static size_t descriptor_table_size = 0;
> >
> > /**
> > * Return a pointer to the pvfs_descriptor for the file descriptor or null
> > * if there is no entry for the given file descriptor
> > */
> > static pvfs_descriptor* pvfs_find_descriptor( int fd )
> > {
> > pvfs_descriptor* pd = 0;
> > int i;
> >
> > for (i = 0; i < descriptor_table_size; ++i)
> > {
> > if (fd == descriptor_table[i].id &&
> > descriptor_table[i].is_in_use) {
> > pd = &(descriptor_table[i]);
> > break;
> > }
> > }
> > return pd;
> > }
> >
> > /**
> > * Allocate a new pvfs_descriptor, with a fd number greater than lower_bound
> > * If the table is not large enough to handle the lower_bound, return 0
> > */
> > static pvfs_descriptor* pvfs_alloc_descriptor( int lower_bound )
> > {
> > const int TABLE_SIZE_INCREMENT = 10;
> > pvfs_descriptor* fd = 0;
> > int descriptor_idx = -1;
> > int i;
> > int index_lb;
> >
> > /* Compute a lower bound for the pvfs table index from the file
> > descriptor lower bound */
> > index_lb = max(0, (long)lower_bound - (long)pvfs_fd_offset);
> >
> > /* Find the first available descriptor greater than lower_bound */
> > for (i = index_lb; i < descriptor_table_size; ++i)
> > {
> > if (!descriptor_table[i].is_in_use)
> > {
> > descriptor_idx = i;
> > break;
> > }
> > }
> >
> > /* If no available descriptor was found and the descriptor_table_size
> > is larger than the lower_bound, increase the number of available
> > descriptors */
> > if (0 <= descriptor_idx)
> > {
> > fd = &descriptor_table[descriptor_idx];
> >
> > /* Set the file descriptor number */
> > fd->id = pvfs_fd_offset + descriptor_idx;
> > fd->is_in_use = 1;
> > }
> > else if (-1 == descriptor_idx &&
> > index_lb <= descriptor_table_size)
> > {
> > pvfs_descriptor *buf;
> > int new_table_size = descriptor_table_size + TABLE_SIZE_INCREMENT;
> >
> > buf = malloc(new_table_size * sizeof(pvfs_descriptor));
> > if (0 != buf)
> > {
> > memcpy(buf, descriptor_table,
> > descriptor_table_size * sizeof(pvfs_descriptor));
> > memset(buf + descriptor_table_size, 0,
> > TABLE_SIZE_INCREMENT * sizeof(pvfs_descriptor));
> > free(descriptor_table);
> > descriptor_idx = descriptor_table_size;
> > descriptor_table = buf;
> > descriptor_table_size = new_table_size;
> >
> > /* Set the file descriptor number */
> > fd = &descriptor_table[descriptor_idx];
> > fd->id = pvfs_fd_offset + descriptor_idx;
> > fd->is_in_use = 1;
> > }
> > }
> >
> > return fd;
> > }
> >
> > /**
> > * Split a pathname into a directory and a filename. If non-null
> > * is passed as the directory or filename, the field will be allocated and
> > * filled with the correct value
> > */
> > static int pvfs_split_pathname( const char *path,
> > char **directory,
> > char **filename)
> > {
> > /* Split path into a directory and filename */
> > int path_length = strlen(path);
> > if ('/' == path[0])
> > {
> > int i;
> > for (i = path_length - 1; i >= 0; --i)
> > {
> > if ( '/' == path[i] )
> > {
> > /* parse the directory */
> > if (0 != directory)
> > {
> > *directory = malloc(i + 1);
> > if (0 != directory)
> > {
> > strncpy(*directory, path, i);
> > (*directory)[i] = '\0';
> > }
> > }
> > /* parse the filename */
> > if (0 != filename)
> > {
> > *filename = malloc(path_length - i + 1);
> > if (0 != filename)
> > {
> > strncpy(*filename, path + i + 1, path_length - i);
> > (*filename)[path_length - i] = '\0';
> > }
> > }
> > break;
> > }
> > }
> > }
> > else
> > {
> > fprintf(stderr, "Error: Not an absolute path: %s\n", path);
> > return PVFS_FD_FAILURE;
> > }
> > return PVFS_FD_SUCCESS;
> > }
> >
> >
> > /**
> > * Perform PVFS initialization tasks
> > */
> > static int pvfs_sys_init()
> > {
> > const PVFS_util_tab* mnt;
> > struct rlimit rl;
> > int rc;
> >
> > /* Initialize the file system with mount points */
> > PVFS_util_init_defaults();
> >
> > /* Use the maximum allowed file descriptor to make sure PVFS file
> > descriptors are distinguishable by being greater than that max */
> > rc = getrlimit(RLIMIT_NOFILE, &rl);
> > pvfs_fd_offset = rl.rlim_max;
> > if (RLIM_INFINITY == pvfs_fd_offset)
> > {
> > pvfs_fd_offset = 0;
> > }
> >
> > /* Mark the initialization complete */
> > pvfs_is_sys_initialized = 1;
> > return PVFS_FD_SUCCESS;
> > }
> >
> > /**
> > * Find the PVFS handle to a file via the PVFS system interface
> > */
> > static int pvfs_lookup_dir( const char *directory,
> > PVFS_object_ref *ref,
> > int *fs_id)
> > {
> > int rc;
> > char pvfs_path[256];
> > PVFS_fs_id lookup_fs_id;
> >
> > /* Determine the fs_id and pvfs_path */
> > rc = PVFS_util_resolve(directory, &lookup_fs_id, pvfs_path, 256);
> >
> > if (0 == rc)
> > {
> > PVFS_credentials credentials;
> > PVFS_sysresp_lookup resp_lookup;
> >
> > credentials.uid = getuid();
> > credentials.gid = getgid();
> > rc = PVFS_sys_lookup(lookup_fs_id, pvfs_path,
> > &credentials, &resp_lookup,
> > PVFS2_LOOKUP_LINK_FOLLOW);
> > *ref = resp_lookup.ref;
> > }
> > else
> > {
> > fprintf(stderr, "Error: No matching fstab entry for %s\n",
> > directory);
> > }
> > *fs_id = lookup_fs_id;
> >
> > return rc;
> > }
> >
> > /**
> > * Create a file via the PVFS system interface
> > */
> > static int pvfs_lookup_file( const char *filename,
> > int fs_id,
> > PVFS_object_ref parent_ref,
> > int follow_links,
> > PVFS_object_ref *ref )
> > {
> > int rc;
> > PVFS_credentials credentials;
> > PVFS_sysresp_lookup resp_lookup;
> >
> > /* Set credentials */
> > memset(&credentials, 0, sizeof(credentials));
> > credentials.uid = getuid();
> > credentials.gid = getgid();
> >
> > /* Contact server */
> > rc = PVFS_sys_ref_lookup(fs_id,
> > (char*)filename,
> > parent_ref,
> > &credentials,
> > &resp_lookup,
> > follow_links);
> > *ref = resp_lookup.ref;
> >
> > return rc;
> > }
> >
> > /**
> > * Create a file via the PVFS system interface
> > */
> > static int pvfs_create_file( const char *filename,
> > mode_t mode,
> > PVFS_object_ref parent_ref,
> > PVFS_object_ref *ref,
> > char *dist )
> > {
> > int rc;
> > mode_t mode_mask;
> > mode_t user_mode;
> > PVFS_sys_attr attributes;
> > PVFS_credentials credentials;
> > PVFS_sysresp_create resp_create;
> > PVFS_sys_dist *new_dist = 0;
> >
> > /* Set attributes */
> > memset(&attributes, 0, sizeof(attributes));
> > attributes.owner = getuid();
> > attributes.group = getgid();
> > attributes.atime = time(NULL);
> > attributes.mtime = attributes.atime;
> > attributes.ctime = attributes.atime;
> > attributes.mask = PVFS_ATTR_SYS_ALL_SETABLE;
> > //attributes.dfile_count = 0;
> > //attributes.perms = 0;
> >
> > /* Extract the users umask (and restore it to the original value) */
> > mode_mask = umask(0);
> > umask(mode_mask);
> > user_mode = mode & ~mode_mask;
> >
> > /* Set file permissions */
> > if (user_mode & S_IXOTH)
> > {
> > attributes.perms |= PVFS_O_EXECUTE;
> > }
> > if (user_mode & S_IWOTH)
> > {
> > attributes.perms |= PVFS_O_WRITE;
> > }
> > if (user_mode & S_IROTH)
> > {
> > attributes.perms |= PVFS_O_READ;
> > }
> > if (user_mode & S_IXGRP)
> > {
> > attributes.perms |= PVFS_G_EXECUTE;
> > }
> > if (user_mode & S_IWGRP)
> > {
> > attributes.perms |= PVFS_G_WRITE;
> > }
> > if (user_mode & S_IRGRP)
> > {
> > attributes.perms |= PVFS_G_READ;
> > }
> > if (user_mode & S_IXUSR)
> > {
> > attributes.perms |= PVFS_U_EXECUTE;
> > }
> > if (user_mode & S_IWUSR)
> > {
> > attributes.perms |= PVFS_U_WRITE;
> > }
> > if (user_mode & S_IRUSR)
> > {
> > attributes.perms |= PVFS_U_READ;
> > }
> >
> > /* Set credentials */
> > memset(&credentials, 0, sizeof(credentials));
> > credentials.uid = attributes.owner;
> > credentials.gid = attributes.group;
> >
> > if (dist != NULL)
> > {
> > char *strips = (char *) malloc (sizeof (char) * 256);
> > strcpy (strips, dist);
> > new_dist = PVFS_sys_dist_lookup ("varstrip_dist");
> > rc = PVFS_sys_dist_setparam (new_dist, "strips", strips);
> > if (rc < 0)
> > {
> > PVFS_perror ("PVFS_sys_dist_setparam", rc);
> > exit (0);
> > }
> > }
> > /* Contact server */
> > rc = PVFS_sys_create((char*)filename,
> > parent_ref,
> > attributes,
> > &credentials,
> > new_dist,
> > &resp_create);
> > *ref = resp_create.ref;
> >
> > return rc;
> > }
> >
> >
> > /* pvfs_close implementation*/
> > int pvfs_close( int fd )
> > {
> > pvfs_descriptor* pd;
> >
> > pd = pvfs_find_descriptor(fd);
> > if (0 == pd)
> > {
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> >
> > /* Reset the descriptor for reuse */
> > memset(pd, 0, sizeof(pd));
> > return PVFS_FD_SUCCESS;
> > }
> >
> > /* pvfs_creat implementation*/
> > int pvfs_creat( const char *pathname, mode_t mode )
> > {
> > int flags;
> >
> > /* call pvfs_open with correct flags */
> > flags = O_CREAT|O_WRONLY|O_TRUNC;
> > return pvfs_open(pathname, flags, NULL, mode);
> > }
> >
> > /* pvfs_creat64 implementation*/
> > int pvfs_creat64( const char *pathname, mode_t mode )
> > {
> > int flags;
> >
> > /* call pvfs_open64 with correct flags */
> > flags = O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE;
> > return pvfs_open(pathname, flags, NULL, mode);
> > }
> >
> > /* pvfs_fcntl implementation */
> > int pvfs_fcntl( int fd, int cmd, ... )
> > {
> > switch (cmd)
> > {
> > /* Copy the given file descriptor */
> > case F_DUPFD:
> > {
> > va_list ap;
> > int fd_lower_bound;
> > pvfs_descriptor* pd;
> > pvfs_descriptor* new_pd;
> >
> > /* Retrieve the descriptor */
> > pd = pvfs_find_descriptor(fd);
> > if (0 == pd)
> > {
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> >
> > /* Allocate a new descriptor */
> > va_start(ap, cmd);
> > fd_lower_bound = va_arg(ap, int);
> > va_end(ap);
> > new_pd = pvfs_alloc_descriptor(fd_lower_bound);
> >
> > /* Copy the file descriptor attributes */
> > new_pd->fs_id = pd->fs_id;
> > new_pd->pvfs_handle = pd->pvfs_handle;
> > new_pd->flags = pd->flags;
> > new_pd->offset = pd->offset;
> > return new_pd->id;
> > }
> > /* Get the exec on close bit */
> > case F_GETFD:
> > {
> > /* PVFS close-on-exec must be 0 */
> > return 0;
> > }
> > /* Get the flags for this file */
> > case F_GETFL:
> > {
> > pvfs_descriptor* pd;
> > pd = pvfs_find_descriptor(fd);
> > if (0 == pd)
> > {
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> > return pd->flags;
> > }
> > /* Set the flags for this file */
> > case F_SETFL:
> > {
> > va_list ap;
> > int new_flags;
> > pvfs_descriptor* pd;
> >
> > /* Retrieve the descriptor */
> > pd = pvfs_find_descriptor(fd);
> > if (0 == pd)
> > {
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> >
> > /* Allocate a new descriptor */
> > va_start(ap, cmd);
> > new_flags = va_arg(ap, int);
> > va_end(ap);
> >
> > pd->flags |= (new_flags & O_APPEND);
> >
> > /* Only flag we allow is the append flag */
> > if (pd->flags & O_APPEND)
> > {
> > pvfs_lseek64(pd->id, 0, SEEK_END);
> > }
> > return PVFS_FD_SUCCESS;
> > }
> > /* Return an error for locking commands */
> > case F_GETLK:
> > case F_SETLK:
> > case F_SETLKW:
> > {
> > errno = ENOLCK;
> > return PVFS_FD_FAILURE;
> > }
> > /* Return an error for notification signal commands */
> > case F_GETOWN:
> > case F_SETOWN:
> > {
> > errno = EINVAL;
> > return PVFS_FD_FAILURE;
> > }
> > default:
> > {
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> > }
> > return PVFS_FD_SUCCESS;
> > }
> >
> > /* pvfs_lseek implementation */
> > off_t pvfs_lseek(int fd, off_t offset, int whence)
> > {
> > return pvfs_lseek64(fd, offset, whence);
> > }
> >
> > /* pvfs_lseek implementation */
> > off64_t pvfs_lseek64(int fd, off64_t offset, int whence)
> > {
> > pvfs_descriptor* pd;
> >
> > /* Find the descriptor */
> > pd = pvfs_find_descriptor(fd);
> > if (0 == pd)
> > {
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> >
> > switch(whence)
> > {
> > case SEEK_SET:
> > {
> > pd->offset = offset;
> > break;
> > }
> > case SEEK_CUR:
> > {
> > pd->offset += offset;
> > break;
> > }
> > case SEEK_END:
> > {
> > PVFS_object_ref file_ref;
> > PVFS_credentials creds;
> > PVFS_sysresp_getattr attributes_resp;
> >
> > /* Construct pinode_reference and from descriptor*/
> > memset(&file_ref, 0, sizeof(file_ref));
> > file_ref.handle = pd->pvfs_handle;
> > file_ref.fs_id = pd->fs_id;
> >
> > /* Construct credentials*/
> > memset(&creds, 0, sizeof(creds));
> > creds.uid = getuid();
> > creds.gid = getgid();
> >
> > /* Get the file's size in bytes as the ending offset */
> > PVFS_sys_getattr(file_ref, PVFS_ATTR_SYS_SIZE,
> > &creds, &attributes_resp);
> >
> > pd->offset = attributes_resp.attr.size + offset;
> > break;
> > }
> > default:
> > {
> > errno = EINVAL;
> > return PVFS_FD_FAILURE;
> > }
> > }
> > return pd->offset;
> > }
> >
> > /* pvfs_open implementation*/
> > int pvfs_open( const char *pathname, int flag, char *dist, ... )
> > {
> > int rc;
> > int follow_link;
> > int descriptor;
> > char *directory;
> > char *filename;
> > PVFS_object_ref file_ref;
> >
> > /* Initialize the system interface for this process */
> > if (!pvfs_is_sys_initialized)
> > {
> > rc = pvfs_sys_init();
> > }
> >
> > /* Split the path into a directory and file */
> > rc = pvfs_split_pathname(pathname, &directory, &filename);
> >
> > if (0 != rc && (0 == directory || 0 == filename))
> > {
> > errno = ENOMEM;
> > return PVFS_FD_FAILURE;
> > }
> > else if (0 != rc)
> > {
> > fprintf(stderr, "Error: %s is not a legal PVFS path.\n", pathname);
> > errno = EACCES;
> > return PVFS_FD_FAILURE;
> > }
> >
> > /* Check the flag to determine if links are followed */
> > if (flag & O_NOFOLLOW)
> > {
> > follow_link = PVFS2_LOOKUP_LINK_NO_FOLLOW;
> > }
> > else
> > {
> > follow_link = PVFS2_LOOKUP_LINK_FOLLOW;
> > }
> >
> > /* Check flag to determine creation behavior */
> > if ( (flag & O_CREAT) && (flag & O_EXCL))
> > {
> > PVFS_object_ref parent_ref;
> > int fs_id = 0;
> >
> > rc = pvfs_lookup_dir(pathname, &parent_ref, &fs_id);
> > if (0 == rc)
> > {
> > mode_t mode = 0;
> > //va_list ap;
> > //va_start(ap, flag);
> > //mode = va_arg(ap, mode_t);
> > //va_end(ap);
> > rc = pvfs_create_file(filename, mode, parent_ref, &file_ref,
> > dist);
> > }
> > else
> > {
> > errno = ENOTDIR;
> > return PVFS_FD_FAILURE;
> > }
> > }
> > else if (flag & O_CREAT)
> > {
> > PVFS_object_ref parent_ref;
> > int fs_id = 0;
> >
> > rc = pvfs_lookup_dir(directory, &parent_ref, &fs_id);
> >
> > if (0 == rc)
> > {
> > rc = pvfs_lookup_file(filename, fs_id, parent_ref,
> > follow_link, &file_ref);
> > }
> >
> > if (0 != rc)
> > {
> > mode_t mode = 0;
> > va_list ap;
> > va_start(ap, dist);
> > mode = va_arg(ap, mode_t);
> > va_end(ap);
> > rc = pvfs_create_file(filename, mode, parent_ref, &file_ref,
> > dist);
> > }
> > }
> > else
> > {
> > PVFS_object_ref parent_ref;
> > int fs_id = 0;
> >
> > rc = pvfs_lookup_dir(directory, &parent_ref, &fs_id);
> > if (0 == rc)
> > {
> > rc = pvfs_lookup_file(filename, fs_id, parent_ref,
> > follow_link, &file_ref);
> > }
> > else
> > {
> > errno = ENOTDIR;
> > return PVFS_FD_FAILURE;
> > }
> > }
> >
> > /* Free directory and filename memory */
> > free(directory);
> > free(filename);
> >
> > /* Translate the pvfs reference into a file descriptor */
> > if (0 == rc)
> > {
> > pvfs_descriptor* pd;
> > pd = pvfs_alloc_descriptor(0);
> > if (0 != pd)
> > {
> > /* Set the file information */
> > pd->fs_id = file_ref.fs_id;
> > pd->pvfs_handle = file_ref.handle;
> > pd->flags = flag;
> > pd->is_in_use = 1;
> >
> > /* Retrieve the descriptor number */
> > descriptor = pd->id;
> > }
> > else
> > {
> > errno = ENOMEM;
> > return PVFS_FD_FAILURE;
> > }
> > }
> > else
> > {
> > /* Inidicate that an error occurred */
> > errno = EACCES;
> > return PVFS_FD_FAILURE;
> > }
> >
> > /* Truncate the file if neccesary */
> > if (flag & O_TRUNC)
> > {
> > PVFS_credentials creds;
> > memset(&creds, 0, sizeof(PVFS_credentials));
> > creds.uid = getuid();
> > creds.gid = getgid();
> > PVFS_sys_truncate(file_ref, 0, &creds);
> > }
> >
> > /* Move to the end of file if necessary */
> > if (flag & O_APPEND)
> > {
> > pvfs_lseek64(descriptor, 0, SEEK_END);
> > }
> >
> > return descriptor;
> > }
> >
> > /* pvfs_open64 implementation*/
> > int pvfs_open64( const char *pathname, int flag, ... )
> > {
> > int rc;
> >
> > flag |= O_LARGEFILE;
> >
> > if (O_CREAT & flag)
> > {
> > va_list ap;
> > mode_t mode = 0;
> >
> > va_start(ap, flag);
> > mode = va_arg(ap, mode_t);
> > va_end(ap);
> > rc = pvfs_open(pathname, flag, NULL, mode);
> > }
> > else
> > {
> > rc = pvfs_open(pathname, flag, NULL);
> > }
> >
> > if (0 != rc)
> > {
> > return PVFS_FD_FAILURE;
> > }
> > return PVFS_FD_SUCCESS;
> > }
> >
> > /* pvfs_read implementation */
> > ssize_t pvfs_read( int fd, void *buf, PVFS_Request data_type, size_t count )
> > {
> > int rc;
> > pvfs_descriptor* pd;
> > PVFS_object_ref file_ref;
> > PVFS_Request file_req;
> > PVFS_Request memory_req;
> > PVFS_credentials creds;
> > PVFS_offset offset;
> > PVFS_sysresp_io read_resp;
> >
> > memset(&file_ref, 0, sizeof(file_ref));
> > memset(&file_req, 0, sizeof(file_req));
> > memset(&memory_req, 0, sizeof(memory_req));
> > memset(&creds, 0, sizeof(creds));
> >
> > /* Find the descriptor */
> > pd = pvfs_find_descriptor(fd);
> > if (0 == pd)
> > {
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> >
> > /* Ensure descriptor is available for read access */
> > if (O_WRONLY & pd->flags)
> > {
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> >
> > /* Construct pinode_reference and offset from descriptor*/
> > file_ref.handle = pd->pvfs_handle;
> > file_ref.fs_id = pd->fs_id;
> > offset = pd->offset;
> >
> > file_req = PVFS_BYTE;
> > rc = PVFS_Request_contiguous(count, data_type, &memory_req);
> > creds.uid = getuid();
> > creds.gid = getgid();
> >
> > if (0 == rc)
> > {
> > rc = PVFS_sys_read(file_ref, data_type, offset,
> > buf, memory_req, &creds, &read_resp);
> > }
> > else
> > {
> > errno = EINVAL;
> > return PVFS_FD_FAILURE;
> > }
> >
> > if (0 != rc)
> > {
> > errno = EIO;
> > return PVFS_FD_FAILURE;
> > }
> >
> > pd->offset += count;
> > return count;
> > }
> >
> > /* pvfs_unlink implementation */
> > int pvfs_unlink( const char *pathname )
> > {
> > int rc = 0;
> > char *directory = 0;
> > char *filename = 0;
> > PVFS_object_ref file_ref;
> >
> > /* Initialize the system interface for this process */
> > if (!pvfs_is_sys_initialized)
> > {
> > rc = pvfs_sys_init();
> > }
> >
> > if (0 == rc)
> > {
> > rc = pvfs_split_pathname(pathname, &directory, &filename);
> > }
> >
> > if (0 == rc)
> > {
> > int fs_id;
> > rc = pvfs_lookup_dir(directory, &file_ref, &fs_id);
> > }
> >
> > if (0 == rc)
> > {
> > PVFS_credentials credentials;
> > credentials.uid = getuid();
> > credentials.gid = getgid();
> > rc = PVFS_sys_remove(filename, file_ref, &credentials);
> > }
> >
> > free(directory);
> > free(filename);
> > if (0 != rc)
> > {
> > return PVFS_FD_FAILURE;
> > }
> > return PVFS_FD_SUCCESS;
> > }
> >
> > /*pvfs_write implementation */
> > ssize_t pvfs_write( int fd, const void *buf, PVFS_Request data_type, size_t
> > count )
> > {
> > int rc;
> > pvfs_descriptor* pd;
> > PVFS_object_ref file_ref;
> > PVFS_Request file_req;
> > PVFS_Request memory_req;
> > PVFS_credentials creds;
> > PVFS_offset offset;
> > PVFS_sysresp_io write_resp;
> >
> > memset(&file_ref, 0, sizeof(file_ref));
> > memset(&file_req, 0, sizeof(file_req));
> > memset(&memory_req, 0, sizeof(memory_req));
> > memset(&creds, 0, sizeof(creds));
> >
> > /* Find the descriptor */
> > pd = pvfs_find_descriptor(fd);
> > if (0 == pd)
> > {
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> >
> > /* Ensure descriptor is available for read access */
> > if (O_RDONLY == (pd->flags & O_ACCMODE))
> > {
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> >
> > /* Construct pinode_reference and offset from descriptor*/
> > file_ref.handle = pd->pvfs_handle;
> > file_ref.fs_id = pd->fs_id;
> >
> > file_req = PVFS_BYTE;
> > rc = PVFS_Request_contiguous(count, data_type, &memory_req);
> > offset = 0;
> > creds.uid = getuid();
> > creds.gid = getgid();
> >
> > if (0 == rc)
> > {
> > rc = PVFS_sys_write(file_ref, data_type, pd->offset,
> > (void*)buf, memory_req, &creds, &write_resp);
> > }
> > else
> > {
> > errno = EINVAL;
> > return PVFS_FD_FAILURE;
> > }
> >
> > if (0 != rc)
> > {
> > errno = EIO;
> > return PVFS_FD_FAILURE;
> > }
> > pd->offset += count;
> > return count;
> > }
> >
> > int pvfs_eof (int fd)
> > {
> > int rc;
> > PVFS_sysresp_getattr attr_resp;
> > pvfs_descriptor* pd;
> > PVFS_object_ref file_ref;
> > PVFS_credentials creds;
> > PVFS_offset offset;
> >
> > memset (&file_ref, 0, sizeof(file_ref));
> > memset (&creds, 0, sizeof(creds));
> >
> > pd = pvfs_find_descriptor (fd);
> > if (pd == 0)
> > {
> > //puts ("olmadiii");
> > errno = EBADF;
> > return PVFS_FD_FAILURE;
> > }
> >
> > file_ref.handle = pd->pvfs_handle;
> > file_ref.fs_id = pd->fs_id;
> > creds.uid = getuid ();
> > creds.gid = getgid ();
> > offset = pd->offset;
> >
> > rc = PVFS_sys_getattr (file_ref, PVFS_ATTR_SYS_SIZE, &creds,
> > &attr_resp);
> > //if (rc <= 0) perror ("asad");
> > printf ("%lu %lu\n", offset, (int64_t)attr_resp.attr.size);
> > if (offset > attr_resp.attr.size) {
> > //perror ("oro");
> > return 1;
> > }
> > return 0;
> > }
> >
> > void pvfs_get (int fd, PVFS_offset *offset, PVFS_size *size)
> > {
> > int rc;
> > PVFS_sysresp_getattr attr_resp;
> > pvfs_descriptor* pd;
> > PVFS_object_ref file_ref;
> > PVFS_credentials creds;
> >
> > memset (&file_ref, 0, sizeof(file_ref));
> > memset (&creds, 0, sizeof(creds));
> >
> > pd = pvfs_find_descriptor (fd);
> > if (pd == 0)
> > {
> > //puts ("olmadiii");
> > errno = EBADF;
> > }
> >
> > file_ref.handle = pd->pvfs_handle;
> > file_ref.fs_id = pd->fs_id;
> > creds.uid = getuid ();
> > creds.gid = getgid ();
> > *offset = pd->offset;
> >
> > rc = PVFS_sys_getattr (file_ref, PVFS_ATTR_SYS_SIZE, &creds,
> > &attr_resp);
> > *size = attr_resp.attr.size;
> > }
> >
> > /*
> > * Local variables:
> > * c-indent-level: 4g
> > * c-basic-offset: 4
> > * End:
> > *
> > * vim: ts=8 sts=4 sw=4 noexpandtab
> > */
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > PVFS2-users mailing list
> > [email protected]
> > http://www.beowulf-underground.org/mailman/listinfo/pvfs2-users
>
>
_______________________________________________
PVFS2-users mailing list
[email protected]
http://www.beowulf-underground.org/mailman/listinfo/pvfs2-users