Revision 82cc3ee8 hw/virtio-9p.c

b/hw/virtio-9p.c
3154 3154
    qemu_free(vs);
3155 3155
}
3156 3156

  
3157
/*
3158
 * Implement posix byte range locking code
3159
 * Server side handling of locking code is very simple, because 9p server in
3160
 * QEMU can handle only one client. And most of the lock handling
3161
 * (like conflict, merging) etc is done by the VFS layer itself, so no need to
3162
 * do any thing in * qemu 9p server side lock code path.
3163
 * So when a TLOCK request comes, always return success
3164
 */
3165

  
3166
static void v9fs_lock(V9fsState *s, V9fsPDU *pdu)
3167
{
3168
    int32_t fid, err = 0;
3169
    V9fsLockState *vs;
3170

  
3171
    vs = qemu_mallocz(sizeof(*vs));
3172
    vs->pdu = pdu;
3173
    vs->offset = 7;
3174

  
3175
    vs->flock = qemu_malloc(sizeof(*vs->flock));
3176
    pdu_unmarshal(vs->pdu, vs->offset, "dbdqqds", &fid, &vs->flock->type,
3177
                &vs->flock->flags, &vs->flock->start, &vs->flock->length,
3178
                            &vs->flock->proc_id, &vs->flock->client_id);
3179

  
3180
    vs->status = P9_LOCK_ERROR;
3181

  
3182
    /* We support only block flag now (that too ignored currently) */
3183
    if (vs->flock->flags & ~P9_LOCK_FLAGS_BLOCK) {
3184
        err = -EINVAL;
3185
        goto out;
3186
    }
3187
    vs->fidp = lookup_fid(s, fid);
3188
    if (vs->fidp == NULL) {
3189
        err = -ENOENT;
3190
        goto out;
3191
    }
3192

  
3193
    err = v9fs_do_fstat(s, vs->fidp->fs.fd, &vs->stbuf);
3194
    if (err < 0) {
3195
        err = -errno;
3196
        goto out;
3197
    }
3198
    vs->status = P9_LOCK_SUCCESS;
3199
out:
3200
    vs->offset += pdu_marshal(vs->pdu, vs->offset, "b", vs->status);
3201
    complete_pdu(s, vs->pdu, err);
3202
    qemu_free(vs->flock);
3203
    qemu_free(vs);
3204
}
3205

  
3157 3206
static void v9fs_mkdir_post_lstat(V9fsState *s, V9fsMkState *vs, int err)
3158 3207
{
3159 3208
    if (err == -1) {
......
3416 3465
    [P9_TXATTRCREATE] = v9fs_xattrcreate,
3417 3466
    [P9_TMKNOD] = v9fs_mknod,
3418 3467
    [P9_TRENAME] = v9fs_rename,
3468
    [P9_TLOCK] = v9fs_lock,
3419 3469
    [P9_TMKDIR] = v9fs_mkdir,
3420 3470
    [P9_TVERSION] = v9fs_version,
3421 3471
    [P9_TLOPEN] = v9fs_open,

Also available in: Unified diff