Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/fileio.c

    r740 r988  
    2626#include "smbprofile.h"
    2727
    28 static bool setup_write_cache(files_struct *, SMB_OFF_T);
     28struct write_cache {
     29        off_t file_size;
     30        off_t offset;
     31        size_t alloc_size;
     32        size_t data_size;
     33        char *data;
     34};
     35
     36static bool setup_write_cache(files_struct *, off_t);
    2937
    3038/****************************************************************************
     
    3240****************************************************************************/
    3341
    34 static bool read_from_write_cache(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
    35 {
    36         write_cache *wcp = fsp->wcp;
     42static bool read_from_write_cache(files_struct *fsp,char *data,off_t pos,size_t n)
     43{
     44        struct write_cache *wcp = fsp->wcp;
    3745
    3846        if(!wcp) {
     
    4654        memcpy(data, wcp->data + (pos - wcp->offset), n);
    4755
    48         DO_PROFILE_INC(writecache_read_hits);
     56        DO_PROFILE_INC(writecache_cached_reads);
    4957
    5058        return True;
     
    5563****************************************************************************/
    5664
    57 ssize_t read_file(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
    58 {
    59         ssize_t ret=0,readret;
     65ssize_t read_file(files_struct *fsp,char *data,off_t pos,size_t n)
     66{
     67        ssize_t ret = 0;
    6068
    6169        /* you can't read from print files */
     
    7583        }
    7684
    77         flush_write_cache(fsp, READ_FLUSH);
     85        flush_write_cache(fsp, SAMBA_READ_FLUSH);
    7886
    7987        fsp->fh->pos = pos;
    8088
    8189        if (n > 0) {
    82 #ifdef DMF_FIX
    83                 int numretries = 3;
    84 tryagain:
    85                 readret = SMB_VFS_PREAD(fsp,data,n,pos);
    86 
    87                 if (readret == -1) {
    88                         if ((errno == EAGAIN) && numretries) {
    89                                 DEBUG(3,("read_file EAGAIN retry in 10 seconds\n"));
    90                                 (void)sleep(10);
    91                                 --numretries;
    92                                 goto tryagain;
    93                         }
     90                ret = SMB_VFS_PREAD(fsp,data,n,pos);
     91
     92                if (ret == -1) {
    9493                        return -1;
    95                 }
    96 #else /* NO DMF fix. */
    97                 readret = SMB_VFS_PREAD(fsp,data,n,pos);
    98 
    99                 if (readret == -1) {
    100                         return -1;
    101                 }
    102 #endif
    103                 if (readret > 0) {
    104                         ret += readret;
    10594                }
    10695        }
     
    122111                                files_struct *fsp,
    123112                                const char *data,
    124                                 SMB_OFF_T pos,
     113                                off_t pos,
    125114                                size_t n)
    126115{
     
    164153{
    165154        int ret;
    166         write_cache *wcp = fsp->wcp;
     155        struct write_cache *wcp = fsp->wcp;
    167156
    168157        wcp->file_size = wcp->offset + wcp->data_size;
     
    176165}
    177166
    178 void update_write_time_handler(struct event_context *ctx,
    179                                       struct timed_event *te,
     167void update_write_time_handler(struct tevent_context *ctx,
     168                                      struct tevent_timer *te,
    180169                                      struct timeval now,
    181170                                      void *private_data)
     
    205194        int delay;
    206195
    207         if (fsp->posix_open) {
     196        if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
    208197                /* Don't use delayed writes on POSIX files. */
    209198                return;
     
    241230        /* trigger the update 2 seconds later */
    242231        fsp->update_write_time_event =
    243                 event_add_timed(smbd_event_context(), NULL,
    244                                 timeval_current_ofs(0, delay),
    245                                 update_write_time_handler, fsp);
     232                tevent_add_timer(fsp->conn->sconn->ev_ctx, NULL,
     233                                 timeval_current_ofs_usec(delay),
     234                                 update_write_time_handler, fsp);
    246235}
    247236
     
    250239        struct smb_file_time ft;
    251240
    252         if (fsp->posix_open) {
     241        if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
    253242                /* Don't use delayed writes on POSIX files. */
    254243                return;
     
    281270}
    282271
     272void mark_file_modified(files_struct *fsp)
     273{
     274        int dosmode;
     275
     276        if (fsp->modified) {
     277                return;
     278        }
     279
     280        fsp->modified = true;
     281
     282        if (SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) != 0) {
     283                return;
     284        }
     285        trigger_write_time_update(fsp);
     286
     287        if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
     288                return;
     289        }
     290        if (!(lp_store_dos_attributes(SNUM(fsp->conn)) ||
     291              MAP_ARCHIVE(fsp->conn))) {
     292                return;
     293        }
     294
     295        dosmode = dos_mode(fsp->conn, fsp->fsp_name);
     296        if (IS_DOS_ARCHIVE(dosmode)) {
     297                return;
     298        }
     299        file_set_dosmode(fsp->conn, fsp->fsp_name,
     300                         dosmode | FILE_ATTRIBUTE_ARCHIVE, NULL, false);
     301}
     302
    283303/****************************************************************************
    284304 Write to a file.
     
    288308                        files_struct *fsp,
    289309                        const char *data,
    290                         SMB_OFF_T pos,
     310                        off_t pos,
    291311                        size_t n)
    292312{
    293         write_cache *wcp = fsp->wcp;
     313        struct write_cache *wcp = fsp->wcp;
    294314        ssize_t total_written = 0;
    295315        int write_path = -1;
     
    312332        }
    313333
    314         if (!fsp->modified) {
    315                 fsp->modified = True;
    316 
    317                 if (SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) == 0) {
    318                         trigger_write_time_update(fsp);
    319                         if (!fsp->posix_open &&
    320                                         (lp_store_dos_attributes(SNUM(fsp->conn)) ||
    321                                         MAP_ARCHIVE(fsp->conn))) {
    322                                 int dosmode = dos_mode(fsp->conn, fsp->fsp_name);
    323                                 if (!IS_DOS_ARCHIVE(dosmode)) {
    324                                         file_set_dosmode(fsp->conn, fsp->fsp_name,
    325                                                  dosmode | FILE_ATTRIBUTE_ARCHIVE, NULL, false);
    326                                 }
    327                         }
    328 
    329                         /*
    330                          * If this is the first write and we have an exclusive oplock then setup
    331                          * the write cache.
    332                          */
    333 
    334                         if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !wcp) {
    335                                 setup_write_cache(fsp,
    336                                                  fsp->fsp_name->st.st_ex_size);
    337                                 wcp = fsp->wcp;
    338                         }
    339                 }
    340         }
    341 
    342 #ifdef WITH_PROFILE
     334        /*
     335         * If this is the first write and we have an exclusive oplock
     336         * then setup the write cache.
     337         */
     338
     339        if (!fsp->modified &&
     340            EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) &&
     341            (wcp == NULL)) {
     342                /*
     343                 * Note: no write cache with leases!
     344                 * as the handles would have to share the write cache
     345                 * that's possible but an improvement for another day...
     346                 */
     347                setup_write_cache(fsp, fsp->fsp_name->st.st_ex_size);
     348                wcp = fsp->wcp;
     349        }
     350
     351        mark_file_modified(fsp);
     352
    343353        DO_PROFILE_INC(writecache_total_writes);
    344354        if (!fsp->oplock_type) {
    345355                DO_PROFILE_INC(writecache_non_oplock_writes);
    346356        }
    347 #endif
    348357
    349358        /*
     
    359368        contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_WRITE);
    360369
    361 #ifdef WITH_PROFILE
    362         if (profile_p && profile_p->writecache_total_writes % 500 == 0) {
    363                 DEBUG(3,("WRITECACHE: initwrites=%u abutted=%u total=%u \
    364 nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
    365                         profile_p->writecache_init_writes,
    366                         profile_p->writecache_abutted_writes,
    367                         profile_p->writecache_total_writes,
    368                         profile_p->writecache_non_oplock_writes,
    369                         profile_p->writecache_allocated_write_caches,
    370                         profile_p->writecache_num_write_caches,
    371                         profile_p->writecache_direct_writes,
    372                         profile_p->writecache_num_perfect_writes,
    373                         profile_p->writecache_read_hits ));
    374 
    375                 DEBUG(3,("WRITECACHE: Flushes SEEK=%d, READ=%d, WRITE=%d, READRAW=%d, OPLOCK=%d, CLOSE=%d, SYNC=%d\n",
    376                         profile_p->writecache_flushed_writes[SEEK_FLUSH],
    377                         profile_p->writecache_flushed_writes[READ_FLUSH],
    378                         profile_p->writecache_flushed_writes[WRITE_FLUSH],
    379                         profile_p->writecache_flushed_writes[READRAW_FLUSH],
    380                         profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH],
    381                         profile_p->writecache_flushed_writes[CLOSE_FLUSH],
    382                         profile_p->writecache_flushed_writes[SYNC_FLUSH] ));
    383         }
    384 #endif
    385 
    386370        if (wcp && req->unread_bytes) {
    387371                /* If we're using receivefile don't
    388372                 * deal with a write cache.
    389373                 */
    390                 flush_write_cache(fsp, WRITE_FLUSH);
     374                flush_write_cache(fsp, SAMBA_WRITE_FLUSH);
    391375                delete_write_cache(fsp);
    392376                wcp = NULL;
     
    684668                        */
    685669
    686                         flush_write_cache(fsp, WRITE_FLUSH);
     670                        flush_write_cache(fsp, SAMBA_WRITE_FLUSH);
    687671                        wcp->offset = wcp->file_size;
    688672                        wcp->data_size = pos - wcp->file_size + 1;
     
    788772
    789773                if (cache_flush_needed) {
    790                         DEBUG(3,("WRITE_FLUSH:%d: due to noncontinuous write: fd = %d, size = %.0f, pos = %.0f, \
     774                        DEBUG(3,("SAMBA_WRITE_FLUSH:%d: due to noncontinuous write: fd = %d, size = %.0f, pos = %.0f, \
    791775n = %u, wcp->offset=%.0f, wcp->data_size=%u\n",
    792776                                write_path, fsp->fh->fd, (double)wcp->file_size, (double)pos, (unsigned int)n,
    793777                                (double)wcp->offset, (unsigned int)wcp->data_size ));
    794778
    795                         flush_write_cache(fsp, WRITE_FLUSH);
     779                        flush_write_cache(fsp, SAMBA_WRITE_FLUSH);
    796780                }
    797781        }
     
    821805
    822806        if (n) {
    823 #ifdef WITH_PROFILE
     807                DO_PROFILE_INC(writecache_cached_writes);
    824808                if (wcp->data_size) {
    825809                        DO_PROFILE_INC(writecache_abutted_writes);
     
    827811                        DO_PROFILE_INC(writecache_init_writes);
    828812                }
    829 #endif
    830813
    831814                if ((wcp->data_size == 0)
     
    851834                if (wcp->data_size == 0) {
    852835                        wcp->offset = pos;
    853                         DO_PROFILE_INC(writecache_num_write_caches);
    854836                }
    855837                wcp->data_size += n;
     
    880862void delete_write_cache(files_struct *fsp)
    881863{
    882         write_cache *wcp;
     864        struct write_cache *wcp;
    883865
    884866        if(!fsp) {
     
    890872        }
    891873
    892         DO_PROFILE_DEC(writecache_allocated_write_caches);
     874        DO_PROFILE_INC(writecache_deallocations);
    893875        allocated_write_caches--;
    894876
     
    906888****************************************************************************/
    907889
    908 static bool setup_write_cache(files_struct *fsp, SMB_OFF_T file_size)
     890static bool setup_write_cache(files_struct *fsp, off_t file_size)
    909891{
    910892        ssize_t alloc_size = lp_write_cache_size(SNUM(fsp->conn));
    911         write_cache *wcp;
     893        struct write_cache *wcp;
    912894
    913895        if (allocated_write_caches >= MAX_WRITE_CACHES) {
     
    919901        }
    920902
    921         if((wcp = SMB_MALLOC_P(write_cache)) == NULL) {
     903        if((wcp = SMB_MALLOC_P(struct write_cache)) == NULL) {
    922904                DEBUG(0,("setup_write_cache: malloc fail.\n"));
    923905                return False;
     
    938920
    939921        fsp->wcp = wcp;
    940         DO_PROFILE_INC(writecache_allocated_write_caches);
     922        DO_PROFILE_INC(writecache_allocations);
    941923        allocated_write_caches++;
    942924
     
    951933****************************************************************************/
    952934
    953 void set_filelen_write_cache(files_struct *fsp, SMB_OFF_T file_size)
     935void set_filelen_write_cache(files_struct *fsp, off_t file_size)
    954936{
    955937        if(fsp->wcp) {
     
    976958ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason)
    977959{
    978         write_cache *wcp = fsp->wcp;
     960        struct write_cache *wcp = fsp->wcp;
    979961        size_t data_size;
    980962        ssize_t ret;
     
    987969        wcp->data_size = 0;
    988970
    989         DO_PROFILE_DEC_INC(writecache_num_write_caches,writecache_flushed_writes[reason]);
     971        switch (reason) {
     972        case SAMBA_SEEK_FLUSH:
     973                DO_PROFILE_INC(writecache_flush_reason_seek);
     974                break;
     975        case SAMBA_READ_FLUSH:
     976                DO_PROFILE_INC(writecache_flush_reason_read);
     977                break;
     978        case SAMBA_WRITE_FLUSH:
     979                DO_PROFILE_INC(writecache_flush_reason_write);;
     980                break;
     981        case SAMBA_READRAW_FLUSH:
     982                DO_PROFILE_INC(writecache_flush_reason_readraw);
     983                break;
     984        case SAMBA_OPLOCK_RELEASE_FLUSH:
     985                DO_PROFILE_INC(writecache_flush_reason_oplock);
     986                break;
     987        case SAMBA_CLOSE_FLUSH:
     988                DO_PROFILE_INC(writecache_flush_reason_close);
     989                break;
     990        case SAMBA_SYNC_FLUSH:
     991                DO_PROFILE_INC(writecache_flush_reason_sync);
     992                break;
     993        case SAMBA_SIZECHANGE_FLUSH:
     994                DO_PROFILE_INC(writecache_flush_reason_sizechange);
     995                break;
     996        default:
     997                break;
     998        }
    990999
    9911000        DEBUG(9,("flushing write cache: fd = %d, off=%.0f, size=%u\n",
    9921001                fsp->fh->fd, (double)wcp->offset, (unsigned int)data_size));
    9931002
    994 #ifdef WITH_PROFILE
    9951003        if(data_size == wcp->alloc_size) {
    996                 DO_PROFILE_INC(writecache_num_perfect_writes);
    997         }
    998 #endif
     1004                DO_PROFILE_INC(writecache_perfect_writes);
     1005        }
    9991006
    10001007        ret = real_write_file(NULL, fsp, wcp->data, wcp->offset, data_size);
     
    10211028
    10221029        if (lp_strict_sync(SNUM(conn)) &&
    1023             (lp_syncalways(SNUM(conn)) || write_through)) {
    1024                 int ret = flush_write_cache(fsp, SYNC_FLUSH);
     1030            (lp_sync_always(SNUM(conn)) || write_through)) {
     1031                int ret = flush_write_cache(fsp, SAMBA_SYNC_FLUSH);
    10251032                if (ret == -1) {
    10261033                        return map_nt_error_from_unix(errno);
     
    10411048{
    10421049        if (fsp->fh->fd == -1) {
    1043                 if (fsp->posix_open) {
     1050                if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
    10441051                        return SMB_VFS_LSTAT(fsp->conn, fsp->fsp_name);
    10451052                } else {
Note: See TracChangeset for help on using the changeset viewer.