From 22b6ad9df2e4d9608e47b262d69927bf5958bd44 Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Fri, 17 Dec 2010 17:41:14 +0100 Subject: [PATCH] Disable locking --- etc/afpd/fork.c | 4 +-- include/atalk/adouble.h | 3 +- libatalk/adouble/ad_lock.c | 40 ++++++++++++++-------- libatalk/adouble/ad_lock.h | 17 +--------- libatalk/adouble/ad_open.c | 68 +++++++++++--------------------------- 5 files changed, 51 insertions(+), 81 deletions(-) diff --git a/etc/afpd/fork.c b/etc/afpd/fork.c index 851dc2f2..35d05152 100644 --- a/etc/afpd/fork.c +++ b/etc/afpd/fork.c @@ -427,8 +427,8 @@ int afp_openfork(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, si goto openfork_err; break; default: - LOG(log_error, logtype_afpd, "afp_openfork('%s/%s'): ad_open: errno: %i (%s)", - getcwdpath, s_path->m_name, errno, strerror(errno) ); + LOG(log_error, logtype_afpd, "afp_openfork(\"%s\"): %s", + abspath(s_path->m_name), strerror(errno) ); goto openfork_err; break; } diff --git a/include/atalk/adouble.h b/include/atalk/adouble.h index 37e4e531..ec7f3893 100644 --- a/include/atalk/adouble.h +++ b/include/atalk/adouble.h @@ -161,8 +161,10 @@ struct ad_fd { char *adf_syml; int adf_flags; int adf_excl; +#if 0 adf_lock_t *adf_lock; int adf_refcount, adf_lockcount, adf_lockmax; +#endif }; /* some header protection */ @@ -199,7 +201,6 @@ struct adouble { bstring ad_fullpath; /* adouble EA need this */ struct adouble_fops *ad_ops; uint16_t ad_open_forks; /* open forks (by others) */ - char ad_data[AD_DATASZ_MAX]; }; diff --git a/libatalk/adouble/ad_lock.c b/libatalk/adouble/ad_lock.c index e31133cb..49006e13 100644 --- a/libatalk/adouble/ad_lock.c +++ b/libatalk/adouble/ad_lock.c @@ -66,9 +66,9 @@ static int XLATE_FCNTL_LOCK(int type) /* ----------------------- */ static int OVERLAP(off_t a, off_t alen, off_t b, off_t blen) { - return (!alen && a <= b) || - (!blen && b <= a) || - ( (a + alen > b) && (b + blen > a) ); + return (!alen && a <= b) || + (!blen && b <= a) || + ( (a + alen > b) && (b + blen > a) ); } /* allocation for lock regions. we allocate aggressively and shrink @@ -79,6 +79,7 @@ static int OVERLAP(off_t a, off_t alen, off_t b, off_t blen) /* remove a lock and compact space if necessary */ static void adf_freelock(struct ad_fd *ad, const int i) { +#if 0 adf_lock_t *lock = ad->adf_lock + i; if (--(*lock->refcount) < 1) { @@ -111,6 +112,7 @@ static void adf_freelock(struct ad_fd *ad, const int i) ad->adf_lockmax = ad->adf_lockcount + ARRAY_FREE_DELTA; } } +#endif } @@ -123,6 +125,7 @@ static void adf_freelock(struct ad_fd *ad, const int i) */ static void adf_unlock(struct ad_fd *ad, const int fork) { +#if 0 adf_lock_t *lock = ad->adf_lock; int i; @@ -137,13 +140,14 @@ static void adf_unlock(struct ad_fd *ad, const int fork) lock = ad->adf_lock; } } +#endif } /* relock any byte lock that overlaps off/len. unlock everything * else. */ -static void adf_relockrange(struct ad_fd *ad, int fd, - const off_t off, const off_t len) +static void adf_relockrange(struct ad_fd *ad, int fd, off_t off, off_t len) { +#if 0 adf_lock_t *lock = ad->adf_lock; int i; @@ -151,15 +155,17 @@ static void adf_relockrange(struct ad_fd *ad, int fd, if (OVERLAP(off, len, lock[i].lock.l_start, lock[i].lock.l_len)) set_lock(fd, F_SETLK, &lock[i].lock); } +#endif } /* find a byte lock that overlaps off/len for a particular open fork */ static int adf_findlock(struct ad_fd *ad, - const int fork, const int type, - const off_t off, - const off_t len) + const int fork, const int type, + const off_t off, + const off_t len) { +#if 0 adf_lock_t *lock = ad->adf_lock; int i; @@ -171,17 +177,18 @@ static int adf_findlock(struct ad_fd *ad, return i; } } - +#endif return -1; } /* search other fork lock lists */ static int adf_findxlock(struct ad_fd *ad, - const int fork, const int type, - const off_t off, - const off_t len) + const int fork, const int type, + const off_t off, + const off_t len) { +#if 0 adf_lock_t *lock = ad->adf_lock; int i; @@ -192,6 +199,7 @@ static int adf_findxlock(struct ad_fd *ad, OVERLAP(off, len, lock[i].lock.l_start, lock[i].lock.l_len)) return i; } +#endif return -1; } @@ -262,8 +270,9 @@ int start = off; /* ------------------ */ int ad_fcntl_lock(struct adouble *ad, const u_int32_t eid, const int locktype, - const off_t off, const off_t len, const int fork) + const off_t off, const off_t len, const int fork) { +#if 0 struct flock lock; struct ad_fd *adf; adf_lock_t *adflock; @@ -401,6 +410,8 @@ fcntl_lock_err: lock.l_type = F_UNLCK; if (!adf->adf_excl) set_lock(adf->adf_fd, F_SETLK, &lock); return -1; +#endif + return 0; } /* ------------------------- @@ -413,6 +424,7 @@ fcntl_lock_err: */ static int testlock(struct ad_fd *adf, off_t off, off_t len) { +#if 0 struct flock lock; adf_lock_t *plock; int i; @@ -441,6 +453,8 @@ static int testlock(struct ad_fd *adf, off_t off, off_t len) return 0; } return 1; +#endif + return 0; } /* --------------- */ diff --git a/libatalk/adouble/ad_lock.h b/libatalk/adouble/ad_lock.h index 490bff26..8e7860d2 100644 --- a/libatalk/adouble/ad_lock.h +++ b/libatalk/adouble/ad_lock.h @@ -7,24 +7,9 @@ * around. that way, we can honor locks created by the same process * with the same file. */ -#define adf_lock_init(a) \ - do { \ - (a)->adf_lockmax = (a)->adf_lockcount = 0; \ - (a)->adf_excl = 0;(a)->adf_lock = NULL; \ - } while (0) - #define adf_lock_free(a) \ do { \ - int i; \ - if ((a)->adf_lock != NULL) { \ - for (i = 0; i < (a)->adf_lockcount; i++) { \ - adf_lock_t *lock = (a)->adf_lock + i; \ - if (--(*lock->refcount) < 1) \ - free(lock->refcount); \ - } \ - free((a)->adf_lock); \ - adf_lock_init(a); \ - } \ + ; \ } while (0) #endif /* libatalk/adouble/ad_private.h */ diff --git a/libatalk/adouble/ad_open.c b/libatalk/adouble/ad_open.c index fc6e27c8..93fb0354 100644 --- a/libatalk/adouble/ad_open.c +++ b/libatalk/adouble/ad_open.c @@ -523,7 +523,6 @@ static int ad_open_df(const char *path, int adflags, int oflags, int mode, struc /* just created, set owner if admin (root) */ ad_chown(path, &st_dir); } - adf_lock_init(&ad->ad_data_fork); } else { /* the file is already open... but */ if ((oflags & ( O_RDWR | O_WRONLY)) @@ -541,7 +540,6 @@ static int ad_open_df(const char *path, int adflags, int oflags, int mode, struc * idem for ressource fork. */ } - ad->ad_data_fork.adf_refcount++; return 0; } @@ -694,26 +692,8 @@ static int ad_open_hf(const char *path, int adflags, int oflags, int mode, struc LOG(log_maxdebug, logtype_default, "ad_open_hf(\"%s/%s\", adf: 0x%04x, of: 0x%04x)", getcwdpath(), path, adflags, oflags); - if (ad->ad_md->adf_refcount) { - /* the file is already open */ - if ((oflags & ( O_RDWR | O_WRONLY)) - && !(ad->ad_md->adf_flags & ( O_RDWR | O_WRONLY))) { - if ((adflags & ADFLAGS_HF) && ad->ad_data_fork.adf_refcount) - /* We just have openend the df, so we have to close it now */ - ad_close(ad, ADFLAGS_DF); - errno = EACCES; - return -1; - } - ad_refresh(ad); - /* it's not new anymore */ - ad->ad_md->adf_flags &= ~( O_TRUNC | O_CREAT ); - ad->ad_md->adf_refcount++; - return 0; - } - memset(ad->ad_eid, 0, sizeof( ad->ad_eid )); ad->ad_rlen = 0; - adf_lock_init(ad->ad_md); switch (ad->ad_flags) { case AD_VERSION2: @@ -727,8 +707,6 @@ static int ad_open_hf(const char *path, int adflags, int oflags, int mode, struc break; } - ad->ad_md->adf_refcount = 1; - return ret; } @@ -743,21 +721,21 @@ static int ad_open_rf(const char *path, int adflags, int oflags, int mode, struc if (ad->ad_flags != AD_VERSION_EA) return 0; - LOG(log_maxdebug, logtype_default, "ad_open_hf_ea(\"%s\", adf: 0x%04x, of: 0x%04x)", + LOG(log_debug, logtype_default, "ad_open_rf(\"%s\", adf: 0x%04x, of: 0x%04x)", abspath(path), adflags, oflags); - if (ad->ad_resource_fork.adf_refcount) { - /* already open */ - ad->ad_resource_fork.adf_flags &= ~( O_TRUNC | O_CREAT ); /* not new anymore */ - free(ad->ad_resforkbuf); - ad->ad_resforkbuf = NULL; - } else { - adf_lock_init(&ad->ad_resource_fork); + if ((ad->ad_rlen = sys_lgetxattr(cfrombstr(ad->ad_fullpath), AD_EA_RESO, NULL, 0)) <= 0) { + switch (errno) { + case ENOATTR: + ad->ad_rlen = 0; + break; + default: + LOG(log_warning, logtype_default, "ad_open_rf(\"%s\"): %s", + abspath(path), strerror(errno)); + return -1; + } } - if ((ad->ad_rlen = sys_lgetxattr(cfrombstr(ad->ad_fullpath), AD_EA_RESO, NULL, 0)) <= 0) - return -1; - /* Round up and allocate buffer */ size_t roundup = ((ad->ad_rlen / RFORK_EA_ALLOCSIZE) + 1) * RFORK_EA_ALLOCSIZE; if ((ad->ad_resforkbuf = malloc(roundup)) == NULL) @@ -769,9 +747,6 @@ static int ad_open_rf(const char *path, int adflags, int oflags, int mode, struc if (sys_lgetxattr(cfrombstr(ad->ad_fullpath), AD_EA_META, ad->ad_resforkbuf, ad->ad_rlen) == -1) return -1; - ad->ad_resource_fork.adf_refcount++; - -exit: if (ret != 0) { free(ad->ad_resforkbuf); ad->ad_resforkbuf = NULL; @@ -960,6 +935,7 @@ void ad_init(struct adouble *ad, int flags, int options) ad_data_fileno(ad) = -1; ad_reso_fileno(ad) = -1; ad_meta_fileno(ad) = -1; + ad->ad_inited = AD_INITED; } static const char *adflags2logstr(int adflags) @@ -1019,7 +995,7 @@ static const char *oflags2logstr(int oflags) buf[0] = 0; - if ((oflags & O_RDONLY) == O_RDONLY) { + if (oflags == O_RDONLY) { strlcat(buf, "O_RDONLY", 64); first = 0; } @@ -1085,24 +1061,18 @@ int ad_open(const char *path, int adflags, int oflags, int mode, struct adouble LOG(log_debug, logtype_default, "ad_open(\"%s\", %s, %s, 0%04o)", abspath(path), adflags2logstr(adflags), oflags2logstr(oflags), mode); - if (ad->ad_inited != AD_INITED) { + if (ad->ad_inited != AD_INITED) + AFP_PANIC("ad_open: not initialized"); + + if (ad->ad_fullpath == NULL) { if ((ad->ad_fullpath = bfromcstr(abspath(path))) == NULL) { ret = -1; goto exit; } - ad->ad_inited = AD_INITED; - ad->ad_refcount = 1; - ad->ad_open_forks = 0; - ad->ad_resource_fork.adf_refcount = 0; - ad->ad_data_fork.adf_refcount = 0; - ad->ad_data_fork.adf_syml = 0; - } else { - ad->ad_open_forks = ((ad->ad_data_fork.adf_refcount > 0) ? ATTRBIT_DOPEN : 0); - /* XXX not true if we have a meta data fork ? */ - if ((ad->ad_resource_fork.adf_refcount > ad->ad_data_fork.adf_refcount)) - ad->ad_open_forks |= ATTRBIT_ROPEN; } + ad->ad_refcount++; + if ((adflags & ADFLAGS_DF)) { if (ad_open_df(path, adflags, oflags, mode, ad) != 0) { ret = -1; -- 2.39.2