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

« back to all changes in this revision

Viewing changes to src/util/hooks.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:
73
73
              "start",
74
74
              "stopped",
75
75
              "prepare",
76
 
              "release")
 
76
              "release",
 
77
              "migrate")
77
78
 
78
79
VIR_ENUM_IMPL(virHookLxcOp, VIR_HOOK_LXC_OP_LAST,
79
80
              "start",
141
142
    for (i = 0;i < VIR_HOOK_DRIVER_LAST;i++) {
142
143
        res = virHookCheck(i, virHookDriverTypeToString(i));
143
144
        if (res < 0)
144
 
            return(-1);
 
145
            return -1;
145
146
 
146
147
        if (res == 1) {
147
148
            virHooksFound |= (1 << i);
148
149
            ret++;
149
150
        }
150
151
    }
151
 
    return(ret);
 
152
    return ret;
152
153
}
153
154
 
154
155
/**
164
165
virHookPresent(int driver) {
165
166
    if ((driver < VIR_HOOK_DRIVER_DAEMON) ||
166
167
        (driver >= VIR_HOOK_DRIVER_LAST))
167
 
        return(0);
 
168
        return 0;
168
169
    if (virHooksFound == -1)
169
 
        return(0);
 
170
        return 0;
170
171
 
171
172
    if ((virHooksFound & (1 << driver)) == 0)
172
 
        return(0);
173
 
    return(1);
 
173
        return 0;
 
174
    return 1;
174
175
}
175
176
 
176
 
/*
 
177
/**
177
178
 * virHookCall:
178
179
 * @driver: the driver number (from virHookDriver enum)
179
180
 * @id: an id for the object '-' if non available for example on daemon hooks
181
182
 * @sub_op: a sub_operation, currently unused
182
183
 * @extra: optional string information
183
184
 * @input: extra input given to the script on stdin
 
185
 * @output: optional address of variable to store malloced result buffer
184
186
 *
185
187
 * Implement a hook call, where the external script for the driver is
186
188
 * called with the given information. This is a synchronous call, we wait for
187
 
 * execution completion
 
189
 * execution completion. If @output is non-NULL, *output is guaranteed to be
 
190
 * allocated after successful virHookCall, and is best-effort allocated after
 
191
 * failed virHookCall; the caller is responsible for freeing *output.
188
192
 *
189
193
 * Returns: 0 if the execution succeeded, 1 if the script was not found or
190
194
 *          invalid parameters, and -1 if script returned an error
191
195
 */
192
196
int
193
 
virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
194
 
            const char *input) {
 
197
virHookCall(int driver,
 
198
            const char *id,
 
199
            int op,
 
200
            int sub_op,
 
201
            const char *extra,
 
202
            const char *input,
 
203
            char **output)
 
204
{
195
205
    int ret;
196
206
    int exitstatus;
197
207
    char *path;
200
210
    const char *opstr;
201
211
    const char *subopstr;
202
212
 
 
213
    if (output)
 
214
        *output = NULL;
 
215
 
203
216
    if ((driver < VIR_HOOK_DRIVER_DAEMON) ||
204
217
        (driver >= VIR_HOOK_DRIVER_LAST))
205
 
        return(1);
 
218
        return 1;
206
219
 
207
220
    /*
208
221
     * We cache the availability of the script to minimize impact at
215
228
        virHookInitialize();
216
229
 
217
230
    if ((virHooksFound & (1 << driver)) == 0)
218
 
        return(1);
 
231
        return 1;
219
232
 
220
233
    drvstr = virHookDriverTypeToString(driver);
221
234
 
235
248
        virHookReportError(VIR_ERR_INTERNAL_ERROR,
236
249
                           _("Hook for %s, failed to find operation #%d"),
237
250
                           drvstr, op);
238
 
        return(1);
 
251
        return 1;
239
252
    }
240
253
    subopstr = virHookSubopTypeToString(sub_op);
241
254
    if (subopstr == NULL)
248
261
        virHookReportError(VIR_ERR_INTERNAL_ERROR,
249
262
                           _("Failed to build path for %s hook"),
250
263
                           drvstr);
251
 
        return(-1);
 
264
        return -1;
252
265
    }
253
266
 
254
267
    cmd = virCommandNewArgList(path, id, opstr, subopstr, extra, NULL);
257
270
 
258
271
    if (input)
259
272
        virCommandSetInputBuffer(cmd, input);
 
273
    if (output)
 
274
        virCommandSetOutputBuffer(cmd, output);
260
275
 
261
276
    ret = virCommandRun(cmd, &exitstatus);
262
277
    if (ret == 0 && exitstatus != 0) {