~ubuntu-branches/debian/sid/glusterfs/sid

« back to all changes in this revision

Viewing changes to libglusterfs/src/store.c

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2014-04-22 10:00:41 UTC
  • mfrom: (1.3.25)
  • Revision ID: package-import@ubuntu.com-20140422100041-6mur2ttyvb8zzpfq
Tags: 3.5.0-1
* New upstream release.
  - Rewrite patch 01-spelling-error.
  - Adjust lintian overrides.
  - Install new files.
  - The offical tarball is not properly generated, hack it around.
  - Add symlink from fusermount-glusterfs manpage to mount.glusterfs.
  - Move gsync-sync-gfid from /usr/share to /usr/lib.
  - Add benchmarking directory.
* Remove old versioned build dependencies and build depend on libglib2.0-dev.
* Add lintian override for possible-gpl-code-linked-with-openssl. It is the
  same false positive like with the gluster-server package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
221
221
 
222
222
        GF_ASSERT (handle);
223
223
 
224
 
        handle->fd = open (handle->path, O_RDWR);
 
224
        if (handle->locked == F_ULOCK)
 
225
                /* no locking is used handle->fd gets closed() after usage */
 
226
                handle->fd = open (handle->path, O_RDWR);
 
227
        else
 
228
                /* handle->fd is valid already, kept open for lockf() */
 
229
                lseek (handle->fd, 0, SEEK_SET);
225
230
 
226
231
        if (handle->fd == -1) {
227
232
                gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %s",
229
234
                goto out;
230
235
        }
231
236
        if (!handle->read)
232
 
                handle->read = fdopen (handle->fd, "r");
 
237
                handle->read = fdopen (dup(handle->fd), "r");
 
238
        else
 
239
                fseek (handle->read, 0, SEEK_SET);
233
240
 
234
241
        if (!handle->read) {
235
242
                gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %s",
278
285
                }
279
286
        } while (1);
280
287
out:
281
 
        if (handle->fd > 0) {
 
288
        if (handle->read) {
 
289
                fclose (handle->read);
 
290
                handle->read = NULL;
 
291
        }
 
292
 
 
293
        if (handle->fd > 0 && handle->locked == F_ULOCK) {
 
294
                /* only invalidate handle->fd if not locked */
282
295
                close (handle->fd);
283
 
                handle->read = NULL;
284
296
        }
285
297
 
286
298
        GF_FREE (free_str);
366
378
                goto out;
367
379
 
368
380
        shandle->path = spath;
 
381
        shandle->locked = F_ULOCK;
369
382
        *handle = shandle;
370
383
 
371
384
        ret = 0;
390
403
 
391
404
        ret = stat (path, &statbuf);
392
405
        if (ret) {
393
 
                gf_log ("", GF_LOG_ERROR, "Unable to retrieve store handle "
394
 
                        "%s, error: %s", path, strerror (errno));
 
406
                gf_log ("", GF_LOG_ERROR, "Path corresponding to "
 
407
                        "%s, returned error: (%s)",
 
408
                        path, strerror (errno));
395
409
                goto out;
396
410
        }
397
411
        ret =  gf_store_handle_new (path, handle);
630
644
        }
631
645
        return "Invalid errno";
632
646
}
 
647
 
 
648
int
 
649
gf_store_lock (gf_store_handle_t *sh)
 
650
{
 
651
        int                     ret;
 
652
 
 
653
        GF_ASSERT (sh);
 
654
        GF_ASSERT (sh->path);
 
655
        GF_ASSERT (sh->locked == F_ULOCK);
 
656
 
 
657
        sh->fd = open (sh->path, O_RDWR);
 
658
        if (sh->fd == -1) {
 
659
                gf_log ("", GF_LOG_ERROR, "Failed to open '%s': %s", sh->path,
 
660
                        strerror (errno));
 
661
                return -1;
 
662
        }
 
663
 
 
664
        ret = lockf (sh->fd, F_LOCK, 0);
 
665
        if (ret)
 
666
                gf_log ("", GF_LOG_ERROR, "Failed to gain lock on '%s': %s",
 
667
                        sh->path, strerror (errno));
 
668
        else
 
669
                /* sh->locked is protected by the lockf(sh->fd) above */
 
670
                sh->locked = F_LOCK;
 
671
 
 
672
        return ret;
 
673
}
 
674
 
 
675
void
 
676
gf_store_unlock (gf_store_handle_t *sh)
 
677
{
 
678
        GF_ASSERT (sh);
 
679
        GF_ASSERT (sh->locked == F_LOCK);
 
680
 
 
681
        sh->locked = F_ULOCK;
 
682
        lockf (sh->fd, F_ULOCK, 0);
 
683
        close (sh->fd);
 
684
}
 
685
 
 
686
int
 
687
gf_store_locked_local (gf_store_handle_t *sh)
 
688
{
 
689
        GF_ASSERT (sh);
 
690
 
 
691
        return (sh->locked == F_LOCK);
 
692
}