Ignore:
Timestamp:
May 19, 2016, 2:25:59 PM (9 years ago)
Author:
dmik
Message:

tdb: Revert open/lock code to vendor.

This effectively reverts r895, r896 and many earlier commits that would
all attempt to solve the issues with file advisory locking provided by
fcntl() and used to serialize access to TDB files in Samba. All these
issues are to be solved by a proper fcntl() lock implementation provided
now by the new libcx library (https://github.com/bitwiseworks/libcx).

With the current version of libcx tdbtorture works flawlessly for
-n > 1 (it may run out of memory returning ENOLCK but that's a separate
issue that will be solved soon).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/lib/tdb/common/open.c

    r901 r905  
    1  /*
     1 /* 
    22   Unix SMB/CIFS implementation.
    33
     
    120120}
    121121
    122 /* open the database, creating it if necessary
     122/* open the database, creating it if necessary 
    123123
    124124   The open_flags and mode are passed straight to the open call on the
     
    126126   is advisory, use zero for a default value.
    127127
    128    Return is NULL on error, in which case errno is also set.  Don't
     128   Return is NULL on error, in which case errno is also set.  Don't 
    129129   try to call tdb_error or tdb_errname, just do strerror(errno).
    130130
     
    162162        return check_header_hash(tdb, false, m1, m2);
    163163}
    164 
    165 #ifdef __OS2__
    166 static int os2_create_lockfile(struct tdb_context *tdb, const char *name, const char *origin)
    167 {
    168         /* name could be null, so handle it */
    169         if (name == NULL)
    170                 return 0;
    171 
    172         char lock_name[_MAX_PATH + 5];
    173         snprintf(lock_name, sizeof(lock_name), "%s.lock", name);
    174         /*
    175          * First try to O_TRUNC it to make sure the file is empty (this
    176          * will succeed on first open), but ignore the error that will
    177          * happen if some bytes are already locked.
    178          */
    179         tdb->lock_fd = open(lock_name, tdb->open_flags | O_CREAT | O_TRUNC, 0777);
    180         if (tdb->lock_fd == -1 && errno == EACCES)
    181                 tdb->lock_fd = open(lock_name, tdb->open_flags | O_CREAT, 0777);
    182         if (tdb->lock_fd == -1) {
    183                 TDB_LOG((tdb, TDB_DEBUG_ERROR, "os2_create_lockfile: cannot create lock file %s, errno=%d\n",
    184                          lock_name, errno));
    185                 return -1;
    186         }
    187 
    188         return 0;
    189 }
    190 #endif
    191164
    192165_PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
     
    333306        fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC);
    334307
    335 #ifdef __OS2__
    336         if (os2_create_lockfile(tdb, name, "tdb_open_ex") != 0)
    337                 goto fail;
    338 #endif
    339 
    340308        /* ensure there is only one process initialising at once */
    341309        if (tdb_nest_lock(tdb, OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) {
     
    505473        { int save_errno = errno;
    506474
    507 #ifdef __OS2__
    508         close(tdb->lock_fd);
    509         tdb->lock_fd = -1;
    510 #endif
    511475        if (!tdb)
    512476                return NULL;
     
    577541        }
    578542
    579 #ifdef __OS2__
    580         close(tdb->lock_fd);
    581         tdb->lock_fd = -1;
    582 #endif
    583 
    584543#ifdef TDB_TRACE
    585544        close(tdb->tracefd);
     
    649608#endif /* fake pread or pwrite */
    650609
    651 #ifdef __OS2__
    652         close(tdb->lock_fd);
    653         tdb->lock_fd = -1;
    654 
    655         if (os2_create_lockfile(tdb, tdb->name, "tdb_reopen") != 0)
    656                 goto fail;
    657 #endif
    658610        /* We may still think we hold the active lock. */
    659611        tdb->num_lockrecs = 0;
Note: See TracChangeset for help on using the changeset viewer.