summaryrefslogtreecommitdiffstats
path: root/tests/bugs/bug-834465.c
blob: 61d3deac0771f518536248d949ffe5a258e212ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <sys/file.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int
main (int argc, char *argv[])
{
        int          fd       = -1;
        char        *filename = NULL;
        struct flock lock     = {0, };
        int          i        = 0;
        int          ret      = -1;

        if (argc != 2) {
                fprintf (stderr, "Usage: %s <filename> ", argv[0]);
                goto out;
        }

        filename = argv[1];

        fd = open (filename, O_RDWR | O_CREAT, 0);
        if (fd < 0) {
                fprintf (stderr, "open (%s) failed (%s)\n", filename,
                         strerror (errno));
                goto out;
        }

        lock.l_type = F_WRLCK;
        lock.l_whence = SEEK_SET;
        lock.l_start = 1;
        lock.l_len = 1;

        while (i < 100) {
                lock.l_type = F_WRLCK;
                ret = fcntl (fd, F_SETLK, &lock);
                if (ret < 0) {
                        fprintf (stderr, "fcntl setlk failed (%s)\n",
                                        strerror (errno));
                        goto out;
                }

                lock.l_type = F_UNLCK;
                ret = fcntl (fd, F_SETLK, &lock);
                if (ret < 0) {
                        fprintf (stderr, "fcntl setlk failed (%s)\n",
                                        strerror (errno));
                        goto out;
                }

                i++;
        }

        ret = 0;

out:
        return ret;
}
s.git/tree/xlators/storage/posix/src/posix.c?h=v3.5.0&id=4c20b5377e4a73a684ba3bb091380fd0f19731ca'>xlators/storage/posix/src/posix.c
@@ -1125,6 +1125,13 @@ posix_releasedir (xlator_t *this,
priv = this->private;
+ if (!pfd->path) {
+ op_errno = EBADFD;
+ gf_log (this->name, GF_LOG_DEBUG,
+ "pfd->path was NULL. fd=%p pfd=%p",
+ fd, pfd);
+ }
+
pthread_mutex_lock (&priv->janitor_lock);
{
INIT_LIST_HEAD (&pfd->list);
@@ -1133,14 +1140,6 @@ posix_releasedir (xlator_t *this,
}
pthread_mutex_unlock (&priv->janitor_lock);
- if (!pfd->path) {
- op_errno = EBADFD;
- gf_log (this->name, GF_LOG_DEBUG,
- "pfd->path was NULL. fd=%p pfd=%p",
- fd, pfd);
- goto out;
- }
-
op_ret = 0;
out:
@@ -2782,23 +2781,22 @@ posix_release (xlator_t *this,
_fd = pfd->fd;
- pthread_mutex_lock (&priv->janitor_lock);
- {
- INIT_LIST_HEAD (&pfd->list);
- list_add_tail (&pfd->list, &priv->janitor_fds);
- pthread_cond_signal (&priv->janitor_cond);
- }
- pthread_mutex_unlock (&priv->janitor_lock);
-
if (pfd->dir) {
op_ret = -1;
op_errno = EBADF;
gf_log (this->name, GF_LOG_DEBUG,
"pfd->dir is %p (not NULL) for file fd=%p",
pfd->dir, fd);
- goto out;
}
+ pthread_mutex_lock (&priv->janitor_lock);
+ {
+ INIT_LIST_HEAD (&pfd->list);
+ list_add_tail (&pfd->list, &priv->janitor_fds);
+ pthread_cond_signal (&priv->janitor_cond);
+ }
+ pthread_mutex_unlock (&priv->janitor_lock);
+
LOCK (&priv->lock);
{
priv->stats.nr_files--;