~serge-hallyn/ubuntu/raring/libvirt/libvirt-hugepages

« back to all changes in this revision

Viewing changes to src/fdstream.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-13 15:44:12 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20120513154412-fgmn5sxqdzgnzlx3
Tags: 0.9.12-0ubuntu1
* New upstream version:
  * Synchronize with debian packaging:
    - debian/control: Update build depends.
    - debian/libvirt-bin.postrm: Cleanup /var/log/libvirt
      on purge.
    - Bump standards verson (no changes).
    - debian/patches/Don-t-fail-if-we-can-t-setup-avahi.patch: Added
  * Dropped patches:
    - debian/patches/Debianize-libvirt-guests.patch
    - debian/patches/rewrite-lxc-controller-eof-handling-yet-again
    - debian/patches/ubuntu/libnl13.patch
    - debian/patches/ubuntu/fix-lxc-startup-error.patch
    - debian/patches/ubuntu/fix-bridge-fd.patch
    - debian/patches/ubuntu/skip-labelling-network-disks.patch
    - debian/patches/ubuntu/xen-xend-shutdown-detection.patch
    - debian/patches/ubuntu/xen-config-no-vfb-for-hvm.patch
    - debian/patches/debian/Disable-daemon-start-test.patch
    - debian/patches/debian/Disable-gnulib-s-test-nonplocking-pipe.sh.patch
    - debian/patches/ubuntu/9006-default-config-test-case.patch
    - debian/patches/fix-block-migration.patch
    - debian/patches/ubuntu/9022-qemu-unescape-HMP-commands-before-converting-them-to.patch
    - debian/patches/ubuntu/9023-qemu-change-rbd-auth_supported-separation-character-.patch
    - debian/patches/ubuntu/9024-qemu-allow-snapshotting-of-sheepdog-and-rbd-disks.patch
    - debian/patches/9025-qemu-change-rbd-auth_supported-separation-character-.patch
    - debian/patches/ubuntu/arm-gcc-workaround.patch
  * Rediffed:
    - debian/patches/Allow-libvirt-group-to-access-the-socket.patch
    - debian/patches/Disable-failing-virnetsockettest.patch
    - debian/patches/dnsmasq-as-priv-user
    - debian/patches/9002-better_default_uri_virsh.patch
  * debian/control: Add libnl-route-3-dev ass a build depends.
  * debian/patches/libnl3-build-fix.patch: Fix build with libnl3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * fdstream.h: generic streams impl for file descriptors
 
2
 * fdstream.c: generic streams impl for file descriptors
3
3
 *
4
 
 * Copyright (C) 2009-2011 Red Hat, Inc.
 
4
 * Copyright (C) 2009-2012 Red Hat, Inc.
5
5
 *
6
6
 * This library is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU Lesser General Public
55
55
    unsigned long long length;
56
56
 
57
57
    int watch;
 
58
    int events;         /* events the stream callback is subscribed for */
58
59
    bool cbRemoved;
59
60
    bool dispatching;
60
61
    bool closed;
62
63
    void *opaque;
63
64
    virFreeCallback ff;
64
65
 
 
66
    /* don't call the abort callback more than once */
 
67
    bool abortCallbackCalled;
 
68
    bool abortCallbackDispatching;
 
69
 
 
70
    /* internal callback, as the regular one (from generic streams) gets
 
71
     * eaten up by the server stream driver */
 
72
    virFDStreamInternalCloseCb icbCb;
 
73
    virFDStreamInternalCloseCbFreeOpaque icbFreeOpaque;
 
74
    void *icbOpaque;
 
75
 
65
76
    virMutex lock;
66
77
};
67
78
 
92
103
    fdst->watch = 0;
93
104
    fdst->ff = NULL;
94
105
    fdst->cb = NULL;
 
106
    fdst->events = 0;
95
107
    fdst->opaque = NULL;
96
108
 
97
109
    ret = 0;
120
132
    }
121
133
 
122
134
    virEventUpdateHandle(fdst->watch, events);
 
135
    fdst->events = events;
123
136
 
124
137
    ret = 0;
125
138
 
214
227
    fdst->cb = cb;
215
228
    fdst->opaque = opaque;
216
229
    fdst->ff = ff;
 
230
    fdst->events = events;
 
231
    fdst->abortCallbackCalled = false;
217
232
    virStreamRef(st);
218
233
 
219
234
    ret = 0;
225
240
 
226
241
 
227
242
static int
228
 
virFDStreamClose(virStreamPtr st)
 
243
virFDStreamCloseInt(virStreamPtr st, bool streamAbort)
229
244
{
230
 
    struct virFDStreamData *fdst = st->privateData;
 
245
    struct virFDStreamData *fdst;
 
246
    virStreamEventCallback cb;
 
247
    void *opaque;
231
248
    int ret;
232
249
 
233
250
    VIR_DEBUG("st=%p", st);
234
251
 
235
 
    if (!fdst)
 
252
    if (!st || !(fdst = st->privateData) || fdst->abortCallbackDispatching)
236
253
        return 0;
237
254
 
238
255
    virMutexLock(&fdst->lock);
239
256
 
 
257
    /* aborting the stream, ensure the callback is called if it's
 
258
     * registered for stream error event */
 
259
    if (streamAbort &&
 
260
        fdst->cb &&
 
261
        (fdst->events & (VIR_STREAM_EVENT_READABLE |
 
262
                         VIR_STREAM_EVENT_WRITABLE))) {
 
263
        /* don't enter this function accidentally from the callback again */
 
264
        if (fdst->abortCallbackCalled) {
 
265
            virMutexUnlock(&fdst->lock);
 
266
            return 0;
 
267
        }
 
268
 
 
269
        fdst->abortCallbackCalled = true;
 
270
        fdst->abortCallbackDispatching = true;
 
271
 
 
272
        /* cache the pointers */
 
273
        cb = fdst->cb;
 
274
        opaque = fdst->opaque;
 
275
        virMutexUnlock(&fdst->lock);
 
276
 
 
277
        /* call failure callback, poll reports nothing on closed fd */
 
278
        (cb)(st, VIR_STREAM_EVENT_ERROR, opaque);
 
279
 
 
280
        virMutexLock(&fdst->lock);
 
281
        fdst->abortCallbackDispatching = false;
 
282
    }
 
283
 
 
284
    /* mutex locked */
240
285
    ret = VIR_CLOSE(fdst->fd);
241
286
    if (fdst->cmd) {
242
287
        char buf[1024];
274
319
 
275
320
    st->privateData = NULL;
276
321
 
 
322
    /* call the internal stream closing callback */
 
323
    if (fdst->icbCb) {
 
324
        /* the mutex is not accessible anymore, as private data is null */
 
325
        (fdst->icbCb)(st, fdst->icbOpaque);
 
326
        if (fdst->icbFreeOpaque)
 
327
            (fdst->icbFreeOpaque)(fdst->icbOpaque);
 
328
    }
 
329
 
277
330
    if (fdst->dispatching) {
278
331
        fdst->closed = true;
279
332
        virMutexUnlock(&fdst->lock);
286
339
    return ret;
287
340
}
288
341
 
 
342
static int
 
343
virFDStreamClose(virStreamPtr st)
 
344
{
 
345
    return virFDStreamCloseInt(st, false);
 
346
}
 
347
 
 
348
static int
 
349
virFDStreamAbort(virStreamPtr st)
 
350
{
 
351
    return virFDStreamCloseInt(st, true);
 
352
}
 
353
 
289
354
static int virFDStreamWrite(virStreamPtr st, const char *bytes, size_t nbytes)
290
355
{
291
356
    struct virFDStreamData *fdst = st->privateData;
392
457
    .streamSend = virFDStreamWrite,
393
458
    .streamRecv = virFDStreamRead,
394
459
    .streamFinish = virFDStreamClose,
395
 
    .streamAbort = virFDStreamClose,
 
460
    .streamAbort = virFDStreamAbort,
396
461
    .streamAddCallback = virFDStreamAddCallback,
397
462
    .streamUpdateCallback = virFDStreamUpdateCallback,
398
463
    .streamRemoveCallback = virFDStreamRemoveCallback
636
701
                                       offset, length,
637
702
                                       oflags | O_CREAT, mode);
638
703
}
 
704
 
 
705
int virFDStreamSetInternalCloseCb(virStreamPtr st,
 
706
                                  virFDStreamInternalCloseCb cb,
 
707
                                  void *opaque,
 
708
                                  virFDStreamInternalCloseCbFreeOpaque fcb)
 
709
{
 
710
    struct virFDStreamData *fdst = st->privateData;
 
711
 
 
712
    virMutexLock(&fdst->lock);
 
713
 
 
714
    if (fdst->icbFreeOpaque)
 
715
        (fdst->icbFreeOpaque)(fdst->icbOpaque);
 
716
 
 
717
    fdst->icbCb = cb;
 
718
    fdst->icbOpaque = opaque;
 
719
    fdst->icbFreeOpaque = fcb;
 
720
 
 
721
    virMutexUnlock(&fdst->lock);
 
722
    return 0;
 
723
}