sdisk.cpp

00001 /* -*- mode:C++; c-basic-offset:4 -*-
00002      Shore-MT -- Multi-threaded port of the SHORE storage manager
00003    
00004                        Copyright (c) 2007-2009
00005       Data Intensive Applications and Systems Labaratory (DIAS)
00006                Ecole Polytechnique Federale de Lausanne
00007    
00008                          All Rights Reserved.
00009    
00010    Permission to use, copy, modify and distribute this software and
00011    its documentation is hereby granted, provided that both the
00012    copyright notice and this permission notice appear in all copies of
00013    the software, derivative works or modified versions, and any
00014    portions thereof, and that both notices appear in supporting
00015    documentation.
00016    
00017    This code is distributed in the hope that it will be useful, but
00018    WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
00020    DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
00021    RESULTING FROM THE USE OF THIS SOFTWARE.
00022 */
00023 
00024 /*<std-header orig-src='shore'>
00025 
00026  $Id: sdisk.cpp,v 1.10 2010/07/29 21:22:57 nhall Exp $
00027 
00028 SHORE -- Scalable Heterogeneous Object REpository
00029 
00030 Copyright (c) 1994-99 Computer Sciences Department, University of
00031                       Wisconsin -- Madison
00032 All Rights Reserved.
00033 
00034 Permission to use, copy, modify and distribute this software and its
00035 documentation is hereby granted, provided that both the copyright
00036 notice and this permission notice appear in all copies of the
00037 software, derivative works or modified versions, and any portions
00038 thereof, and that both notices appear in supporting documentation.
00039 
00040 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00041 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00042 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00043 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00044 
00045 This software was developed with support by the Advanced Research
00046 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00047 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00048 Further funding for this work was provided by DARPA through
00049 Rome Research Laboratory Contract No. F30602-97-2-0247.
00050 
00051 */
00052 
00053 #include "w_defines.h"
00054 
00055 /*  -- do not edit anything above this line --   </std-header>*/
00056 
00057 /**\cond skip */
00058 
00059 /*
00060  *   NewThreads I/O is Copyright 1995, 1996, 1997, 1998 by:
00061  *
00062  *    Josef Burger    <bolo@cs.wisc.edu>
00063  *
00064  *   All Rights Reserved.
00065  *
00066  *   NewThreads I/O may be freely used as long as credit is given
00067  *   to the above author(s) and the above copyright is maintained.
00068  */
00069 
00070 #include <w.h>
00071 #include <sdisk.h>
00072 
00073 #include <sthread.h>    /* XXX for error codes */
00074 
00075 
00076 // DEAD const    int    stSHORTSEEK = sthread_base_t::stSHORTSEEK;
00077 
00078 
00079 int    sdisk_base_t::vsize(const iovec_t *iov, int iovcnt)
00080 {
00081     int    total = 0;
00082 
00083     for (int i = 0; i < iovcnt; i++)
00084         total += iov[i].iov_len;
00085 
00086     return total;
00087 }
00088 
00089 
00090 int    sdisk_t::modeBits(int mode)
00091 {
00092     return mode & MODE_FLAGS;
00093 }
00094 
00095 
00096 /* open mode is a 1-of-n choice */
00097 bool    sdisk_t::hasMode(int mode, int wanted)
00098 {
00099     mode = modeBits(mode);
00100     return mode == wanted;
00101 }
00102 
00103 /* options are one-of-many; true if all wanted are found */
00104 bool    sdisk_t::hasOption(int mode, int wanted)
00105 {
00106     mode &= OPTION_FLAGS;
00107     return (mode & wanted) == wanted;
00108 }
00109 
00110 
00111 /* Emulate vector I/O operations on thos boxes which don't
00112    support it. Either an error or a short transfer will
00113    abort the I/O and return the transfer count. */
00114 
00115 w_rc_t    sdisk_t::readv(const iovec_t *iov, int iovcnt, int &transfered)
00116 {
00117     int    done = 0;
00118     int    n;
00119     int    i;
00120     w_rc_t    e;
00121 
00122     (void) vsize(iov, iovcnt);
00123 
00124     for (i = 0; i < iovcnt; i++) {
00125         e = read(iov[i].iov_base, iov[i].iov_len, n);
00126         if (e.is_error())
00127             break;
00128         done += n;
00129         if (size_t(n) != iov[i].iov_len)
00130             break;
00131     }
00132 
00133     transfered = done;
00134 
00135     return e;
00136 }
00137 
00138 
00139 w_rc_t    sdisk_t::writev(const iovec_t *iov, int iovcnt, int &transfered)
00140 {
00141     int    done = 0;
00142     int    n;
00143     int    i;
00144     w_rc_t    e;
00145 
00146     (void) vsize(iov, iovcnt);
00147 
00148     for (i = 0; i < iovcnt; i++) {
00149         e = write(iov[i].iov_base, iov[i].iov_len, n);
00150         if (e.is_error())
00151             break;
00152         done += n;
00153         if (size_t(n) != iov[i].iov_len)
00154             break;
00155     }
00156 
00157     transfered = done;
00158 
00159     return e;
00160 }
00161 
00162 /* Emulate positioned I/O operations on thos boxes which don't
00163    support it.  It isn't "race safe", that is a difficult problem
00164    to deal with.  Pread/Pwrite don't move the file pointer, but
00165    that is difficult to do if the OS doens't support them.  We 
00166    seek to where the I/O is supposed to be, execute it, and
00167    then restore the old position.  */
00168 
00169 #ifndef DEAD
00170 w_rc_t    sdisk_t::pread(void *, int , fileoff_t , int &)
00171 {
00172   // make it safe or don't do it at all.
00173     return RC(fcNOTIMPLEMENTED);
00174 }
00175 #else //  DEAD
00176 w_rc_t    sdisk_t::pread(void *buf, int size, fileoff_t pos,
00177                int &transfered)
00178 {
00179     fileoff_t    was;
00180     fileoff_t    newpos;
00181     int          n;
00182     w_rc_t       e;
00183     w_rc_t       es;
00184 
00185     W_DO(seek(0, SEEK_AT_CUR, was));
00186     /* Only move if it needs to */
00187     if (pos != was) {
00188         W_DO(seek(pos, SEEK_AT_SET, newpos));
00189         if (newpos != pos) {
00190             es = seek(was, SEEK_AT_SET, newpos);
00191             if (es.is_error())
00192                 cerr << "Warning: pread reposition failed!"
00193                     << endl << e << endl;
00194             return RC(stSHORTSEEK);
00195         }
00196     }
00197 
00198     e = read(buf, size, n);
00199 
00200     es = seek(was, SEEK_AT_SET, newpos);
00201     /* XXX should a reposition error make the I/O fail? */
00202     if (es.is_error() || newpos != was)
00203         cerr << "Warning: pread reposition failed!"
00204             << endl << e << endl;
00205 
00206     transfered = n;
00207 
00208     return e;
00209 }
00210 #endif
00211 
00212 #ifndef DEAD
00213 w_rc_t    sdisk_t::pwrite(const void *, int , fileoff_t ,
00214                int &)
00215 {
00216   // make it safe or don't do it at all.
00217   return RC(fcNOTIMPLEMENTED);
00218 }
00219 #else // DEAD
00220 w_rc_t    sdisk_t::pwrite(const void *buf, int size, fileoff_t pos,
00221                int &transfered)
00222 {
00223   // make it safe or don't do it at all.
00224   return RC(fcNOTIMPLEMENTED);
00225   
00226     fileoff_t    was;
00227     fileoff_t    newpos;
00228     int        n;
00229     w_rc_t        e;
00230     w_rc_t        es;
00231 
00232     W_DO(seek(0, SEEK_AT_CUR, was));
00233     /* Only move if it needs to */
00234     if (pos != was) {
00235         W_DO(seek(pos, SEEK_AT_SET, newpos));
00236         if (newpos != pos) {
00237             es = seek(was, SEEK_AT_SET, newpos);
00238             if (es.is_error())
00239                 cerr << "Warning: pwrite reposition failed!"
00240                     << endl << e << endl;
00241             return RC(stSHORTSEEK);
00242         }
00243     }
00244 
00245     e = write(buf, size, n);
00246 
00247     es = seek(was, SEEK_AT_SET, newpos);
00248     /* XXX should a reposition error make the I/O fail? */
00249     if (es.is_error() || newpos != was)
00250         cerr << "Warning: pwrite reposition failed!"
00251             << endl << e << endl;
00252 
00253     transfered = n;
00254 
00255     return e;
00256 }
00257 #endif
00258 
00259 
00260 /* a no-op file-sync if the underlying implementation doesn't support it. */
00261 w_rc_t    sdisk_t::sync()
00262 {
00263     return RCOK;
00264 }
00265 
00266 
00267 w_rc_t    sdisk_t::stat(filestat_t &)
00268 {
00269     return RC(fcNOTIMPLEMENTED);
00270 }
00271 /**\endcond skip */

Generated on Wed Oct 27 08:48:36 2010 for Shore Storage Manager by  doxygen 1.4.7