Add support for DIOCCACHESYNC ioctl for dm devices. Add new sync function

pointer to dm_target_t because that is the only part of dm which know real
block device. disk_ioctl_switch parses whole device table and for every
entry it calls particular sync routine which propagates DIOCCACHESYNC
to real disk.

While I was here implement some KNF fixes and remove unneeded symbols from
dm.h.

Problem reported on port-xen@ by Hugo Silva.
This commit is contained in:
haad 2010-05-18 15:10:38 +00:00
parent 923bf0dda0
commit fb8751aba4
7 changed files with 140 additions and 37 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: device-mapper.c,v 1.22 2010/03/26 15:46:04 jakllsch Exp $ */
/* $NetBSD: device-mapper.c,v 1.23 2010/05/18 15:10:38 haad Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -152,6 +152,7 @@ MODULE(MODULE_CLASS_DRIVER, dm, NULL);
static int
dm_modcmd(modcmd_t cmd, void *arg)
{
#ifdef _MODULE
int error, bmajor, cmajor;
error = 0;
@ -209,6 +210,9 @@ dm_modcmd(modcmd_t cmd, void *arg)
}
return error;
#else
return ENOTTY;
#endif
}
#endif /* _MODULE */
@ -470,6 +474,32 @@ disk_ioctl_switch(dev_t dev, u_long cmd, void *data)
dm_dev_unbusy(dmv);
break;
}
case DIOCCACHESYNC:
{
dm_table_entry_t *table_en;
dm_table_t *tbl;
int err;
if ((dmv = dm_dev_lookup(NULL, NULL, minor(dev))) == NULL)
return ENODEV;
/* Select active table */
tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_ACTIVE);
/*
* Call sync target routine for all table entries. Target sync
* routine basically call DIOCCACHESYNC on underlying devices.
*/
SLIST_FOREACH(table_en, tbl, next)
{
err = table_en->target->sync(table_en);
}
dm_table_release(&dmv->table_head, DM_TABLE_ACTIVE);
dm_dev_unbusy(dmv);
break;
}
default:
aprint_debug("unknown disk_ioctl called\n");

View File

@ -1,4 +1,4 @@
/* $NetBSD: dm_target.c,v 1.12 2010/01/04 00:14:41 haad Exp $ */
/* $NetBSD: dm_target.c,v 1.13 2010/05/18 15:10:38 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -289,6 +289,7 @@ dm_target_init(void)
dmt->init = &dm_target_linear_init;
dmt->status = &dm_target_linear_status;
dmt->strategy = &dm_target_linear_strategy;
dmt->sync = &dm_target_linear_sync;
dmt->deps = &dm_target_linear_deps;
dmt->destroy = &dm_target_linear_destroy;
dmt->upcall = &dm_target_linear_upcall;
@ -302,39 +303,12 @@ dm_target_init(void)
dmt3->init = &dm_target_stripe_init;
dmt3->status = &dm_target_stripe_status;
dmt3->strategy = &dm_target_stripe_strategy;
dmt3->sync = &dm_target_stripe_sync;
dmt3->deps = &dm_target_stripe_deps;
dmt3->destroy = &dm_target_stripe_destroy;
dmt3->upcall = &dm_target_stripe_upcall;
r = dm_target_insert(dmt3);
#ifdef notyet
dmt5->version[0] = 1;
dmt5->version[1] = 0;
dmt5->version[2] = 5;
strlcpy(dmt5->name, "snapshot", DM_MAX_TYPE_NAME);
dmt5->init = &dm_target_snapshot_init;
dmt5->status = &dm_target_snapshot_status;
dmt5->strategy = &dm_target_snapshot_strategy;
dmt5->deps = &dm_target_snapshot_deps;
dmt5->destroy = &dm_target_snapshot_destroy;
dmt5->upcall = &dm_target_snapshot_upcall;
r = dm_target_insert(dmt5);
dmt6->version[0] = 1;
dmt6->version[1] = 0;
dmt6->version[2] = 5;
strlcpy(dmt6->name, "snapshot-origin", DM_MAX_TYPE_NAME);
dmt6->init = &dm_target_snapshot_orig_init;
dmt6->status = &dm_target_snapshot_orig_status;
dmt6->strategy = &dm_target_snapshot_orig_strategy;
dmt6->deps = &dm_target_snapshot_orig_deps;
dmt6->destroy = &dm_target_snapshot_orig_destroy;
dmt6->upcall = &dm_target_snapshot_orig_upcall;
r = dm_target_insert(dmt6);
#endif
return r;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: dm_target_error.c,v 1.10 2010/01/04 00:12:22 haad Exp $ */
/* $NetBSD: dm_target_error.c,v 1.11 2010/05/18 15:10:38 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -39,6 +39,15 @@
#include "dm.h"
/* dm_target_error.c */
int dm_target_error_init(dm_dev_t *, void**, char *);
char * dm_target_error_status(void *);
int dm_target_error_strategy(dm_table_entry_t *, struct buf *);
int dm_target_error_sync(dm_table_entry_t *);
int dm_target_error_deps(dm_table_entry_t *, prop_array_t);
int dm_target_error_destroy(dm_table_entry_t *);
int dm_target_error_upcall(dm_table_entry_t *, struct buf *);
#ifdef DM_TARGET_MODULE
/*
* Every target can be compiled directly to dm driver or as a
@ -74,6 +83,7 @@ dm_target_error_modcmd(modcmd_t cmd, void *arg)
dmt->init = &dm_target_error_init;
dmt->status = &dm_target_error_status;
dmt->strategy = &dm_target_error_strategy;
dmt->sync = &dm_target_error_sync;
dmt->deps = &dm_target_error_deps;
dmt->destroy = &dm_target_error_destroy;
dmt->upcall = &dm_target_error_upcall;
@ -130,6 +140,13 @@ dm_target_error_strategy(dm_table_entry_t * table_en, struct buf * bp)
return 0;
}
/* Sync underlying disk caches. */
int
dm_target_error_sync(dm_table_entry_t * table_en)
{
return 0;
}
/* Doesn't do anything here. */
int
dm_target_error_destroy(dm_table_entry_t * table_en)

View File

@ -1,4 +1,4 @@
/* $NetBSD: dm_target_linear.c,v 1.9 2010/01/04 00:14:41 haad Exp $ */
/* $NetBSD: dm_target_linear.c,v 1.10 2010/05/18 15:10:38 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -140,6 +140,22 @@ dm_target_linear_strategy(dm_table_entry_t * table_en, struct buf * bp)
return 0;
}
/*
* Sync underlying disk caches.
*/
int
dm_target_linear_sync(dm_table_entry_t * table_en)
{
int cmd;
dm_target_linear_config_t *tlc;
tlc = table_en->target_config;
cmd = 1;
return VOP_IOCTL(tlc->pdev->pdev_vnode, DIOCCACHESYNC, &cmd,
FREAD|FWRITE, kauth_cred_get());
}
/*
* Destroy target specific data. Decrement table pdevs.
*/

View File

@ -1,4 +1,4 @@
/*$NetBSD: dm_target_mirror.c,v 1.8 2010/01/04 00:12:22 haad Exp $*/
/*$NetBSD: dm_target_mirror.c,v 1.9 2010/05/18 15:10:38 haad Exp $*/
/*
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -39,6 +39,15 @@
#include "dm.h"
/* dm_target_mirror.c */
int dm_target_mirror_init(dm_dev_t *, void**, char *);
char * dm_target_mirror_status(void *);
int dm_target_mirror_strategy(dm_table_entry_t *, struct buf *);
int dm_target_mirror_sync(dm_table_entry_t *);
int dm_target_mirror_deps(dm_table_entry_t *, prop_array_t);
int dm_target_mirror_destroy(dm_table_entry_t *);
int dm_target_mirror_upcall(dm_table_entry_t *, struct buf *);
#ifdef DM_TARGET_MODULE
/*
* Every target can be compiled directly to dm driver or as a
@ -74,6 +83,7 @@ dm_target_mirror_modcmd(modcmd_t cmd, void *arg)
dmt->init = &dm_target_mirror_init;
dmt->status = &dm_target_mirror_status;
dmt->strategy = &dm_target_mirror_strategy;
dmt->sync = &dm_target_mirror_sync;
dmt->deps = &dm_target_mirror_deps;
dmt->destroy = &dm_target_mirror_destroy;
dmt->upcall = &dm_target_mirror_upcall;
@ -134,6 +144,13 @@ dm_target_mirror_strategy(dm_table_entry_t * table_en, struct buf * bp)
return 0;
}
/* Sync underlying disk caches. */
int
dm_target_mirror_sync(dm_table_entry_t * table_en)
{
return 0;
}
/* Doesn't do anything here. */
int
dm_target_mirror_destroy(dm_table_entry_t * table_en)

View File

@ -1,4 +1,4 @@
/* $NetBSD: dm_target_snapshot.c,v 1.12 2010/01/04 00:12:22 haad Exp $ */
/* $NetBSD: dm_target_snapshot.c,v 1.13 2010/05/18 15:10:38 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -85,6 +85,23 @@
#include "dm.h"
/* dm_target_snapshot.c */
int dm_target_snapshot_init(dm_dev_t *, void**, char *);
char * dm_target_snapshot_status(void *);
int dm_target_snapshot_strategy(dm_table_entry_t *, struct buf *);
int dm_target_snapshot_deps(dm_table_entry_t *, prop_array_t);
int dm_target_snapshot_destroy(dm_table_entry_t *);
int dm_target_snapshot_upcall(dm_table_entry_t *, struct buf *);
/* dm snapshot origin driver */
int dm_target_snapshot_orig_init(dm_dev_t *, void**, char *);
char * dm_target_snapshot_orig_status(void *);
int dm_target_snapshot_orig_strategy(dm_table_entry_t *, struct buf *);
int dm_target_snapshot_orig_sync(dm_table_entry_t *);
int dm_target_snapshot_orig_deps(dm_table_entry_t *, prop_array_t);
int dm_target_snapshot_orig_destroy(dm_table_entry_t *);
int dm_target_snapshot_orig_upcall(dm_table_entry_t *, struct buf *);
#ifdef DM_TARGET_MODULE
/*
* Every target can be compiled directly to dm driver or as a
@ -140,6 +157,7 @@ dm_target_snapshot_modcmd(modcmd_t cmd, void *arg)
dmt1->init = &dm_target_snapshot_orig_init;
dmt1->status = &dm_target_snapshot_orig_status;
dmt1->strategy = &dm_target_snapshot_orig_strategy;
dmt1->sync = &dm_target_snapshot_orig_sync;
dmt1->deps = &dm_target_snapshot_orig_deps;
dmt1->destroy = &dm_target_snapshot_orig_destroy;
dmt1->upcall = &dm_target_snapshot_orig_upcall;
@ -381,8 +399,7 @@ dm_target_snapshot_upcall(dm_table_entry_t * table_en, struct buf * bp)
* argv: /dev/mapper/my_data_real
*/
int
dm_target_snapshot_orig_init(dm_dev_t * dmv, void **target_config,
prop_dictionary_t dict)
dm_target_snapshot_orig_init(dm_dev_t * dmv, void **target_config, char *params)
{
dm_target_snapshot_origin_config_t *tsoc;
dm_pdev_t *dmp_real;
@ -456,6 +473,21 @@ dm_target_snapshot_orig_strategy(dm_table_entry_t * table_en, struct buf * bp)
return 0;
}
/*
* Sync underlying disk caches.
*/
int
dm_target_snapshot_orig_sync(dm_table_entry_t * table_en)
{
int cmd;
dm_target_snapshot_origin_config_t *tsoc;
tsoc = table_en->target_config;
cmd = 1;
return VOP_IOCTL(tsoc->tsoc_real_dev->pdev_vnode, DIOCCACHESYNC, &cmd, FREAD|FWRITE, kauth_cred_get());
}
/* Decrement pdev and free allocated space. */
int
dm_target_snapshot_orig_destroy(dm_table_entry_t * table_en)

View File

@ -1,4 +1,4 @@
/* $NetBSD: dm_target_zero.c,v 1.10 2010/01/04 00:12:22 haad Exp $ */
/* $NetBSD: dm_target_zero.c,v 1.11 2010/05/18 15:10:38 haad Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -40,6 +40,15 @@
#include "dm.h"
/* dm_target_zero.c */
int dm_target_zero_init(dm_dev_t *, void**, char *);
char * dm_target_zero_status(void *);
int dm_target_zero_strategy(dm_table_entry_t *, struct buf *);
int dm_target_zero_sync(dm_table_entry_t *);
int dm_target_zero_destroy(dm_table_entry_t *);
int dm_target_zero_deps(dm_table_entry_t *, prop_array_t);
int dm_target_zero_upcall(dm_table_entry_t *, struct buf *);
#ifdef DM_TARGET_MODULE
/*
* Every target can be compiled directly to dm driver or as a
@ -75,6 +84,7 @@ dm_target_zero_modcmd(modcmd_t cmd, void *arg)
dmt->init = &dm_target_zero_init;
dmt->status = &dm_target_zero_status;
dmt->strategy = &dm_target_zero_strategy;
dmt->sync = &dm_target_zero_sync;
dmt->deps = &dm_target_zero_deps;
dmt->destroy = &dm_target_zero_destroy;
dmt->upcall = &dm_target_zero_upcall;
@ -139,6 +149,13 @@ dm_target_zero_strategy(dm_table_entry_t * table_en, struct buf * bp)
return 0;
}
/* Sync underlying disk caches. */
int
dm_target_zero_sync(dm_table_entry_t * table_en)
{
return 0;
}
/* Doesn't not need to do anything here. */
int
dm_target_zero_destroy(dm_table_entry_t * table_en)