modules/vfs_prealloc.c

ソースコードを見る。

関数

static int preallocate_space (int fd, SMB_OFF_T size)
static int prealloc_connect (struct vfs_handle_struct *handle, const char *service, const char *user)
static int prealloc_open (vfs_handle_struct *handle, const char *fname, files_struct *fsp, int flags, mode_t mode)
static int prealloc_ftruncate (vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_OFF_T offset)
NTSTATUS vfs_prealloc_init (void)

変数

static int module_debug
static vfs_op_tuple prealloc_op_tuples []


関数

static int preallocate_space ( int  fd,
SMB_OFF_T  size 
) [static]

vfs_prealloc.c54 行で定義されています。

参照先 errerrnomodule_debugstrerror().

参照元 prealloc_ftruncate()prealloc_open().

00055 {
00056         lock_type fl = {0};
00057         int err;
00058 
00059         if (size <= 0) {
00060                 return 0;
00061         }
00062 
00063         fl.l_whence = SEEK_SET;
00064         fl.l_start = 0;
00065         fl.l_len = size;
00066 
00067         /* IMPORTANT: We use RESVSP because we want the extents to be
00068          * allocated, but we don't want the allocation to show up in
00069          * st_size or persist after the close(2).
00070          */
00071 
00072 #if defined(XFS_IOC_RESVSP64)
00073         /* On Linux this comes in via libxfs.h. */
00074         err = xfsctl(NULL, fd, XFS_IOC_RESVSP64, &fl);
00075 #elif defined(F_RESVSP64)
00076         /* On IRIX, this comes from fcntl.h. */
00077         err = fcntl(fd, F_RESVSP64, &fl);
00078 #else
00079         err = -1;
00080         errno = ENOSYS;
00081 #endif
00082 
00083         if (err) {
00084                 DEBUG(module_debug,
00085                         ("%s: preallocate failed on fd=%d size=%lld: %s\n",
00086                         MODULE, fd, (long long)size, strerror(errno)));
00087         }
00088 
00089         return err;
00090 }

static int prealloc_connect ( struct vfs_handle_struct handle,
const char *  service,
const char *  user 
) [static]

vfs_prealloc.c92 行で定義されています。

参照先 handlelp_parm_int()module_debug.

00096 {
00097             module_debug = lp_parm_int(SNUM(handle->conn),
00098                                         MODULE, "debug", 100);
00099 
00100             return SMB_VFS_NEXT_CONNECT(handle, service, user);
00101 }

static int prealloc_open ( vfs_handle_struct handle,
const char *  fname,
files_struct fsp,
int  flags,
mode_t  mode 
) [static]

vfs_prealloc.c103 行で定義されています。

参照先 CASE_LOWERconv_str_size()fdhandlelp_parm_const_string()module_debugpreallocate_space()sizestrnorm().

00108 {
00109         int fd;
00110         off64_t size = 0;
00111 
00112         const char * dot;
00113         char fext[10];
00114 
00115         if (!(flags & (O_CREAT|O_TRUNC))) {
00116                 /* Caller is not intending to rewrite the file. Let's not mess
00117                  * with the allocation in this case.
00118                  */
00119                 goto normal_open;
00120         }
00121 
00122         *fext = '\0';
00123         dot = strrchr(fname, '.');
00124         if (dot && *++dot) {
00125                 if (strlen(dot) < sizeof(fext)) {
00126                         strncpy(fext, dot, sizeof(fext));
00127                         strnorm(fext, CASE_LOWER);
00128                 }
00129         }
00130 
00131         if (*fext == '\0') {
00132                 goto normal_open;
00133         }
00134 
00135         /* Syntax for specifying preallocation size is:
00136          *      MODULE: <extension> = <size>
00137          * where
00138          *      <extension> is the file extension in lower case
00139          *      <size> is a size like 10, 10K, 10M
00140          */
00141         size = conv_str_size(lp_parm_const_string(SNUM(handle->conn), MODULE,
00142                                                     fext, NULL));
00143         if (size <= 0) {
00144                 /* No need to preallocate this file. */
00145                 goto normal_open;
00146         }
00147 
00148         fd = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
00149         if (fd < 0) {
00150                 return fd;
00151         }
00152 
00153         /* Prellocate only if the file is being created or replaced. Note that
00154          * Samba won't ever pass down O_TRUNC, which is why we have to handle
00155          * truncate calls specially.
00156          */
00157         if ((flags & O_CREAT) || (flags & O_TRUNC)) {
00158                 SMB_OFF_T * psize;
00159 
00160                 psize = VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T);
00161                 if (psize == NULL || *psize == -1) {
00162                         return fd;
00163                 }
00164 
00165                 DEBUG(module_debug,
00166                         ("%s: preallocating %s (fd=%d) to %lld bytes\n",
00167                         MODULE, fname, fd, (long long)size));
00168 
00169                 *psize = size;
00170                 if (preallocate_space(fd, *psize) < 0) {
00171                         VFS_REMOVE_FSP_EXTENSION(handle, fsp);
00172                 }
00173         }
00174 
00175         return fd;
00176 
00177 normal_open:
00178         /* We are not creating or replacing a file. Skip the
00179          * preallocation.
00180          */
00181         DEBUG(module_debug, ("%s: skipping preallocation for %s\n",
00182                     MODULE, fname));
00183         return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
00184 }

static int prealloc_ftruncate ( vfs_handle_struct handle,
files_struct fsp,
int  fd,
SMB_OFF_T  offset 
) [static]

vfs_prealloc.c186 行で定義されています。

参照先 handlepreallocate_space().

00190 {
00191         SMB_OFF_T *psize;
00192         int ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, fd, offset);
00193 
00194         /* Maintain the allocated space even in the face of truncates. */
00195         if ((psize = VFS_FETCH_FSP_EXTENSION(handle, fsp))) {
00196                 preallocate_space(fd, *psize);
00197         }
00198 
00199         return ret;
00200 }

NTSTATUS vfs_prealloc_init ( void   ) 

vfs_prealloc.c210 行で定義されています。

参照先 prealloc_op_tuplessmb_register_vfs().

00211 {
00212         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
00213                 MODULE, prealloc_op_tuples);
00214 }


変数

int module_debug [static]

vfs_prealloc.c52 行で定義されています。

vfs_op_tuple prealloc_op_tuples[] [static]

初期値:

 {
        {SMB_VFS_OP(prealloc_open), SMB_VFS_OP_OPEN, SMB_VFS_LAYER_TRANSPARENT},
        {SMB_VFS_OP(prealloc_ftruncate), SMB_VFS_OP_FTRUNCATE, SMB_VFS_LAYER_TRANSPARENT},
        {SMB_VFS_OP(prealloc_connect), SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT},
        {NULL,  SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
}

vfs_prealloc.c202 行で定義されています。

参照元 vfs_prealloc_init().


Sambaに対してSat Aug 29 21:23:52 2009に生成されました。  doxygen 1.4.7