From nobody Wed Oct 29 09:10:30 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524586818839697.7262373433385; Tue, 24 Apr 2018 09:20:18 -0700 (PDT) Received: from localhost ([::1]:59430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fB0fy-0000vF-04 for importer@patchew.org; Tue, 24 Apr 2018 12:20:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAzpd-0008Vz-F3 for qemu-devel@nongnu.org; Tue, 24 Apr 2018 11:26:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAzpb-0000KK-Dl for qemu-devel@nongnu.org; Tue, 24 Apr 2018 11:26:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45638 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAzpR-0008TY-KR; Tue, 24 Apr 2018 11:26:01 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43342406E8B9; Tue, 24 Apr 2018 15:26:01 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-100.ams2.redhat.com [10.36.117.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32B63202342F; Tue, 24 Apr 2018 15:26:00 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 24 Apr 2018 17:25:11 +0200 Message-Id: <20180424152515.25664-30-kwolf@redhat.com> In-Reply-To: <20180424152515.25664-1-kwolf@redhat.com> References: <20180424152515.25664-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 24 Apr 2018 15:26:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 24 Apr 2018 15:26:01 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC PATCH 29/33] job: Switch transactions to JobTxn X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jcody@redhat.com, jsnow@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This doesn't actually move any transaction code to Job yet, but it renames the type for transactions from BlockJobTxn to JobTxn and makes them contain Jobs rather than BlockJobs Signed-off-by: Kevin Wolf --- include/block/block_int.h | 2 +- include/block/blockjob.h | 11 ++++---- include/block/blockjob_int.h | 2 +- include/qemu/job.h | 3 +++ block/backup.c | 2 +- blockdev.c | 14 +++++------ blockjob.c | 60 +++++++++++++++++++++++-----------------= ---- tests/test-blockjob-txn.c | 8 +++--- 8 files changed, 54 insertions(+), 48 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index c4dd1d4bb8..dc1666c0c4 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1017,7 +1017,7 @@ BlockJob *backup_job_create(const char *job_id, Block= DriverState *bs, BlockdevOnError on_target_error, int creation_flags, BlockCompletionFunc *cb, void *opaque, - BlockJobTxn *txn, Error **errp); + JobTxn *txn, Error **errp); =20 void hmp_drive_add_node(Monitor *mon, const char *optstr); =20 diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 91fdbc9042..fbb8f54dc6 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -33,7 +33,7 @@ #define SLICE_TIME 100000000ULL /* ns */ =20 typedef struct BlockJobDriver BlockJobDriver; -typedef struct BlockJobTxn BlockJobTxn; +typedef struct JobTxn JobTxn; =20 /** * BlockJob: @@ -85,8 +85,7 @@ typedef struct BlockJob { /** BlockDriverStates that are involved in this block job */ GSList *nodes; =20 - BlockJobTxn *txn; - QLIST_ENTRY(BlockJob) txn_list; + JobTxn *txn; } BlockJob; =20 /** @@ -273,7 +272,7 @@ void block_job_iostatus_reset(BlockJob *job); * group. Jobs wait for each other before completing. Cancelling one job * cancels all jobs in the transaction. */ -BlockJobTxn *block_job_txn_new(void); +JobTxn *block_job_txn_new(void); =20 /** * block_job_txn_unref: @@ -282,7 +281,7 @@ BlockJobTxn *block_job_txn_new(void); * or block_job_txn_new. If it's the last reference to the object, it will= be * freed. */ -void block_job_txn_unref(BlockJobTxn *txn); +void block_job_txn_unref(JobTxn *txn); =20 /** * block_job_txn_add_job: @@ -293,7 +292,7 @@ void block_job_txn_unref(BlockJobTxn *txn); * The caller must call either block_job_txn_unref() or block_job_complete= d() * to release the reference that is automatically grabbed here. */ -void block_job_txn_add_job(BlockJobTxn *txn, BlockJob *job); +void block_job_txn_add_job(JobTxn *txn, BlockJob *job); =20 /** * block_job_is_internal: diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index fb81d7a09f..13c9924b9c 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -91,7 +91,7 @@ struct BlockJobDriver { * called from a wrapper that is specific to the job type. */ void *block_job_create(const char *job_id, const BlockJobDriver *driver, - BlockJobTxn *txn, BlockDriverState *bs, uint64_t pe= rm, + JobTxn *txn, BlockDriverState *bs, uint64_t perm, uint64_t shared_perm, int64_t speed, int flags, BlockCompletionFunc *cb, void *opaque, Error **errp= ); =20 diff --git a/include/qemu/job.h b/include/qemu/job.h index c5a5d0cfdb..0c8e7e85d0 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -132,6 +132,9 @@ typedef struct Job { =20 /** Element of the list of jobs */ QLIST_ENTRY(Job) job_list; + + /** Element of the list of jobs in a job transaction */ + QLIST_ENTRY(Job) txn_list; } Job; =20 /** diff --git a/block/backup.c b/block/backup.c index a1ad92fbc3..f83b14d8dc 100644 --- a/block/backup.c +++ b/block/backup.c @@ -547,7 +547,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, BlockdevOnError on_target_error, int creation_flags, BlockCompletionFunc *cb, void *opaque, - BlockJobTxn *txn, Error **errp) + JobTxn *txn, Error **errp) { int64_t len; BlockDriverInfo bdi; diff --git a/blockdev.c b/blockdev.c index 31aac7dae6..69471c62b3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1446,7 +1446,7 @@ typedef struct BlkActionOps { struct BlkActionState { TransactionAction *action; const BlkActionOps *ops; - BlockJobTxn *block_job_txn; + JobTxn *block_job_txn; TransactionProperties *txn_props; QSIMPLEQ_ENTRY(BlkActionState) entry; }; @@ -1864,7 +1864,7 @@ typedef struct DriveBackupState { BlockJob *job; } DriveBackupState; =20 -static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn, +static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, Error **errp); =20 static void drive_backup_prepare(BlkActionState *common, Error **errp) @@ -1954,7 +1954,7 @@ typedef struct BlockdevBackupState { BlockJob *job; } BlockdevBackupState; =20 -static BlockJob *do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *t= xn, +static BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn, Error **errp); =20 static void blockdev_backup_prepare(BlkActionState *common, Error **errp) @@ -2243,7 +2243,7 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp) { TransactionActionList *dev_entry =3D dev_list; - BlockJobTxn *block_job_txn =3D NULL; + JobTxn *block_job_txn =3D NULL; BlkActionState *state, *next; Error *local_err =3D NULL; =20 @@ -2251,7 +2251,7 @@ void qmp_transaction(TransactionActionList *dev_list, QSIMPLEQ_INIT(&snap_bdrv_states); =20 /* Does this transaction get canceled as a group on failure? - * If not, we don't really need to make a BlockJobTxn. + * If not, we don't really need to make a JobTxn. */ props =3D get_transaction_properties(props); if (props->completion_mode !=3D ACTION_COMPLETION_MODE_INDIVIDUAL) { @@ -3264,7 +3264,7 @@ out: aio_context_release(aio_context); } =20 -static BlockJob *do_drive_backup(DriveBackup *backup, BlockJobTxn *txn, +static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn, Error **errp) { BlockDriverState *bs; @@ -3434,7 +3434,7 @@ BlockDeviceInfoList *qmp_query_named_block_nodes(Erro= r **errp) return bdrv_named_nodes_list(errp); } =20 -BlockJob *do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *txn, +BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn, Error **errp) { BlockDriverState *bs; diff --git a/blockjob.c b/blockjob.c index 5d91070cd2..3afa0dbdca 100644 --- a/blockjob.c +++ b/blockjob.c @@ -37,13 +37,13 @@ #include "qemu/timer.h" =20 /* Transactional group of block jobs */ -struct BlockJobTxn { +struct JobTxn { =20 /* Is this txn being cancelled? */ bool aborting; =20 /* List of jobs */ - QLIST_HEAD(, BlockJob) jobs; + QLIST_HEAD(, Job) jobs; =20 /* Reference count */ int refcnt; @@ -95,27 +95,27 @@ BlockJob *block_job_get(const char *id) } } =20 -BlockJobTxn *block_job_txn_new(void) +JobTxn *block_job_txn_new(void) { - BlockJobTxn *txn =3D g_new0(BlockJobTxn, 1); + JobTxn *txn =3D g_new0(JobTxn, 1); QLIST_INIT(&txn->jobs); txn->refcnt =3D 1; return txn; } =20 -static void block_job_txn_ref(BlockJobTxn *txn) +static void block_job_txn_ref(JobTxn *txn) { txn->refcnt++; } =20 -void block_job_txn_unref(BlockJobTxn *txn) +void block_job_txn_unref(JobTxn *txn) { if (txn && --txn->refcnt =3D=3D 0) { g_free(txn); } } =20 -void block_job_txn_add_job(BlockJobTxn *txn, BlockJob *job) +void block_job_txn_add_job(JobTxn *txn, BlockJob *job) { if (!txn) { return; @@ -124,14 +124,14 @@ void block_job_txn_add_job(BlockJobTxn *txn, BlockJob= *job) assert(!job->txn); job->txn =3D txn; =20 - QLIST_INSERT_HEAD(&txn->jobs, job, txn_list); + QLIST_INSERT_HEAD(&txn->jobs, &job->job, txn_list); block_job_txn_ref(txn); } =20 void block_job_txn_del_job(BlockJob *job) { if (job->txn) { - QLIST_REMOVE(job, txn_list); + QLIST_REMOVE(&job->job, txn_list); block_job_txn_unref(job->txn); job->txn =3D NULL; } @@ -286,18 +286,22 @@ static void job_cancel_async(Job *job, bool force) job->force_cancel |=3D force; } =20 -static int block_job_txn_apply(BlockJobTxn *txn, int fn(BlockJob *), bool = lock) +static int block_job_txn_apply(JobTxn *txn, int fn(BlockJob *), bool lock) { AioContext *ctx; - BlockJob *job, *next; + Job *job, *next; + BlockJob *bjob; int rc =3D 0; =20 QLIST_FOREACH_SAFE(job, &txn->jobs, txn_list, next) { + assert(is_block_job(job)); + bjob =3D container_of(job, BlockJob, job); + if (lock) { - ctx =3D blk_get_aio_context(job->blk); + ctx =3D job->aio_context; aio_context_acquire(ctx); } - rc =3D fn(job); + rc =3D fn(bjob); if (lock) { aio_context_release(ctx); } @@ -311,8 +315,8 @@ static int block_job_txn_apply(BlockJobTxn *txn, int fn= (BlockJob *), bool lock) static void block_job_completed_txn_abort(BlockJob *job) { AioContext *ctx; - BlockJobTxn *txn =3D job->txn; - BlockJob *other_job; + JobTxn *txn =3D job->txn; + Job *other_job; =20 if (txn->aborting) { /* @@ -325,7 +329,7 @@ static void block_job_completed_txn_abort(BlockJob *job) =20 /* We are the first failed job. Cancel other jobs. */ QLIST_FOREACH(other_job, &txn->jobs, txn_list) { - ctx =3D blk_get_aio_context(other_job->blk); + ctx =3D other_job->aio_context; aio_context_acquire(ctx); } =20 @@ -333,18 +337,18 @@ static void block_job_completed_txn_abort(BlockJob *j= ob) * them; this job, however, may or may not be cancelled, depending * on the caller, so leave it. */ QLIST_FOREACH(other_job, &txn->jobs, txn_list) { - if (other_job !=3D job) { - job_cancel_async(&other_job->job, false); + if (other_job !=3D &job->job) { + job_cancel_async(other_job, false); } } while (!QLIST_EMPTY(&txn->jobs)) { other_job =3D QLIST_FIRST(&txn->jobs); - ctx =3D blk_get_aio_context(other_job->blk); - if (!job_is_completed(&other_job->job)) { - assert(job_is_cancelled(&other_job->job)); - job_finish_sync(&other_job->job, NULL, NULL); + ctx =3D other_job->aio_context; + if (!job_is_completed(other_job)) { + assert(job_is_cancelled(other_job)); + job_finish_sync(other_job, NULL, NULL); } - job_finalize_single(&other_job->job); + job_finalize_single(other_job); aio_context_release(ctx); } =20 @@ -386,8 +390,8 @@ static int block_job_transition_to_pending(BlockJob *jo= b) =20 static void block_job_completed_txn_success(BlockJob *job) { - BlockJobTxn *txn =3D job->txn; - BlockJob *other_job; + JobTxn *txn =3D job->txn; + Job *other_job; =20 job_state_transition(&job->job, JOB_STATUS_WAITING); =20 @@ -396,10 +400,10 @@ static void block_job_completed_txn_success(BlockJob = *job) * txn. */ QLIST_FOREACH(other_job, &txn->jobs, txn_list) { - if (!job_is_completed(&other_job->job)) { + if (!job_is_completed(other_job)) { return; } - assert(other_job->job.ret =3D=3D 0); + assert(other_job->ret =3D=3D 0); } =20 block_job_txn_apply(txn, block_job_transition_to_pending, false); @@ -627,7 +631,7 @@ static void block_job_event_pending(Notifier *n, void *= opaque) */ =20 void *block_job_create(const char *job_id, const BlockJobDriver *driver, - BlockJobTxn *txn, BlockDriverState *bs, uint64_t pe= rm, + JobTxn *txn, BlockDriverState *bs, uint64_t perm, uint64_t shared_perm, int64_t speed, int flags, BlockCompletionFunc *cb, void *opaque, Error **errp) { diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c index 1572f8d96f..ec5d592b68 100644 --- a/tests/test-blockjob-txn.c +++ b/tests/test-blockjob-txn.c @@ -93,7 +93,7 @@ static const BlockJobDriver test_block_job_driver =3D { */ static BlockJob *test_block_job_start(unsigned int iterations, bool use_timer, - int rc, int *result, BlockJobTxn *tx= n) + int rc, int *result, JobTxn *txn) { BlockDriverState *bs; TestBlockJob *s; @@ -122,7 +122,7 @@ static BlockJob *test_block_job_start(unsigned int iter= ations, static void test_single_job(int expected) { BlockJob *job; - BlockJobTxn *txn; + JobTxn *txn; int result =3D -EINPROGRESS; =20 txn =3D block_job_txn_new(); @@ -160,7 +160,7 @@ static void test_pair_jobs(int expected1, int expected2) { BlockJob *job1; BlockJob *job2; - BlockJobTxn *txn; + JobTxn *txn; int result1 =3D -EINPROGRESS; int result2 =3D -EINPROGRESS; =20 @@ -222,7 +222,7 @@ static void test_pair_jobs_fail_cancel_race(void) { BlockJob *job1; BlockJob *job2; - BlockJobTxn *txn; + JobTxn *txn; int result1 =3D -EINPROGRESS; int result2 =3D -EINPROGRESS; =20 --=20 2.13.6