Integrated: 8297385: Remove duplicated null typos in javadoc

2022-11-24 Thread Dongxu Wang
On Wed, 23 Nov 2022 06:58:09 GMT, Dongxu Wang  wrote:

> 8297385: Remove duplicated null typos in javadoc

This pull request has now been integrated.

Changeset: 0ed8b337
Author:    Dongxu Wang 
Committer: Yi Yang 
URL:   
https://git.openjdk.org/jdk/commit/0ed8b337eaa59881a62af5dcc0abb454761f2e71
Stats: 3 lines in 1 file changed: 0 ins; 0 del; 3 mod

8297385: Remove duplicated null typos in javadoc

Reviewed-by: dfuchs, rriggs

-

PR: https://git.openjdk.org/jdk/pull/11311


RFR: 8297385: Remove duplicated null typos in javadoc

2022-11-22 Thread Dongxu Wang
8297385: Remove duplicated null typos in javadoc

-

Commit messages:
 - 8297385: Remove duplicated null typo in javadoc

Changes: https://git.openjdk.org/jdk/pull/11311/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk=11311=00
  Issue: https://bugs.openjdk.org/browse/JDK-8297385
  Stats: 3 lines in 1 file changed: 0 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/11311.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11311/head:pull/11311

PR: https://git.openjdk.org/jdk/pull/11311


Withdrawn: 8297385: Remove duplicated null typos in javadoc

2022-11-22 Thread Dongxu Wang
On Tue, 15 Nov 2022 15:05:45 GMT, Dongxu Wang  wrote:

> 8297385: Remove duplicated null typos in javadoc

This pull request has been closed without being integrated.

-

PR: https://git.openjdk.org/jdk/pull/11169


Re: RFR: 8297385: Remove duplicated null typos in javadoc [v2]

2022-11-22 Thread Dongxu Wang
On Wed, 23 Nov 2022 06:49:56 GMT, Dongxu Wang  wrote:

>> 8297385: Remove duplicated null typos in javadoc
>
> Dongxu Wang has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains two additional 
> commits since the last revision:
> 
>  - Merge branch 'openjdk:master' into master
>  - Minor remove duplicate null typo

Use #11311 instead, close this pr.

-

PR: https://git.openjdk.org/jdk/pull/11169


Re: RFR: 8297385: Remove duplicated null typos in javadoc [v2]

2022-11-22 Thread Dongxu Wang
On Wed, 23 Nov 2022 06:43:56 GMT, Yi Yang  wrote:

> This looks good, but I'm not a Reviewer, you still need an approval from 
> Reviewer.

Thanks

-

PR: https://git.openjdk.org/jdk/pull/11169


Re: RFR: 8297385: Remove duplicated null typos in javadoc [v2]

2022-11-22 Thread Dongxu Wang
> 8297385: Remove duplicated null typos in javadoc

Dongxu Wang has updated the pull request with a new target base due to a merge 
or a rebase. The incremental webrev excludes the unrelated changes brought in 
by the merge/rebase. The pull request contains two additional commits since the 
last revision:

 - Merge branch 'openjdk:master' into master
 - Minor remove duplicate null typo

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/11169/files
  - new: https://git.openjdk.org/jdk/pull/11169/files/65327c89..f731384b

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=11169=01
 - incr: https://webrevs.openjdk.org/?repo=jdk=11169=00-01

  Stats: 44876 lines in 726 files changed: 16653 ins; 16626 del; 11597 mod
  Patch: https://git.openjdk.org/jdk/pull/11169.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11169/head:pull/11169

PR: https://git.openjdk.org/jdk/pull/11169


Re: RFR: 8297385: Remove duplicated null typos in javadoc

2022-11-22 Thread Dongxu Wang
On Tue, 22 Nov 2022 03:33:55 GMT, Yi Yang  wrote:

> > > good catch, do you need a JBS issue for this?
> > 
> > 
> > Thank you if you can help with that.
> 
> I filed https://bugs.openjdk.org/browse/JDK-8297385 for this, you can change 
> your PR title and commit message to [8297385: Remove duplicated null typo in 
> javadoc](https://bugs.openjdk.org/browse/JDK-8297385), OpenJDK robot will 
> guide you remaining processes.

Thank you, can you also help review

-

PR: https://git.openjdk.org/jdk/pull/11169


Re: RFR: 8297385: Remove duplicated null typos in javadoc

2022-11-21 Thread Dongxu Wang
On Mon, 21 Nov 2022 15:16:14 GMT, Yi Yang  wrote:

> good catch, do you need a JBS issue for this?

Thank you if you can help with that.

-

PR: https://git.openjdk.org/jdk/pull/11169


RFR: 8297385: Remove duplicated null typos in javadoc

2022-11-21 Thread Dongxu Wang
8297385: Remove duplicated null typos in javadoc

-

Commit messages:
 - Minor remove duplicate null typo

Changes: https://git.openjdk.org/jdk/pull/11169/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk=11169=00
  Issue: https://bugs.openjdk.org/browse/JDK-8297385
  Stats: 3 lines in 1 file changed: 0 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/11169.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11169/head:pull/11169

PR: https://git.openjdk.org/jdk/pull/11169


sub

2022-05-13 Thread Dongxu Wang



Re: [VOTE] Retire Apache James HUPA

2021-07-26 Thread Dongxu Wang
+1

On Mon, Jul 26, 2021 at 7:38 PM Dongxu 王东旭  wrote:

> +1
>
> ccing Manolo, thank you.
>
> On Mon, Jul 26, 2021 at 10:16 AM Rene Cordier  wrote:
>
>> +1,
>>
>> Rene.
>>
>> On 23/07/2021 16:00, btell...@apache.org wrote:
>> > Hello all,
>> >
>> > Following a first email on the topic [1] I would like to call for a
>> > formal vote on Apache James Hupa retirement.
>> >
>> > [1]
>> https://www.mail-archive.com/server-dev@james.apache.org/msg70575.html
>> >
>> > Rationnals:
>> >   - The latest release (0.3.0) dates from 2012 which is an eternity in
>> > computing.
>> >   - The latest tag on Github is 0.0.3
>> >   - The pom references 0.0.5-SNAPSHOT suggesting that 0.0.4 release is
>> > lost :-(
>> >   - This repository is crippled by multiple CVEs (quick dependabot
>> review):
>> >- CVE-2021-29425 (commons-io)
>> >- GHSA-m6cp-vxjx-65j6 CVE-2017-7656 CVE-2015-2080 CVE-2017-7657
>> > CVE-2019-10241 CVE-2019-10247 (Jetty server)
>> >- CVE-2020-9447 (gwtupload)
>> >- GHSA-g3wg-6mcf-8jj6 (jetty-webapp)
>> >- CVE-2019-17571 (log4j)
>> >- CVE-2016-131 CVE-2016-3092 (commons-fileupload)
>> >   - Sporadic activity since 2012
>> >   - Zero to no exchanges for several years on the mailing lists.
>> >
>> > Given that alternatives exists, given that the project is
>> > likely not mature, unmaintained and unsecure, I propose to retire this
>> > Apache James subproject.
>> >
>> > |Voting rules: - This is a majority vote as stated in [2] for procedural
>> > issues. - The vote starts at Friday 23rd of July 2021, 4pm UTC+7 - The
>> > vote ends at Friday 30th of July 2021, 4pm UTC+7 [2]
>> > https://www.apache.org/foundation/voting.html Following this
>> retirement,
>> > follow up steps are to be taken as described in [3] [3]
>> > https://www.mail-archive.com/server-dev@james.apache.org/msg70585.html
>> | - 1. Get a formal vote on server-dev mailing list
>> >   - 2. Place a RETIRED_PROJECT file marker in the git
>> >   - 3. Add a note in the project README
>> >   - 4. Retire the ISSUE trackers (Project names HUPA and POSTAGE)
>> >   - 5. Announce it on gene...@james.apache.org and announce@apache
>> >   - 6. Add a notice to the Apache website, if present
>> >   - 7. Remove releases from downloads.apache.org
>> >   - 8. Add notices on the Apache release archives (example
>> > https://archive.apache.org/dist/ant/antidote/ <
>> https://archive.apache.org/dist/ant/antidote/>)
>> >
>> > Best regards,
>> >
>> > Benoit Tellier
>> > ||
>> >
>> >
>> > -
>> > To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
>> > For additional commands, e-mail: server-dev-h...@james.apache.org
>> >
>> >
>>
>> -
>> To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
>> For additional commands, e-mail: server-dev-h...@james.apache.org
>>
>>


[no subject]

2019-03-06 Thread Dongxu Wang



[jira] [Assigned] (HUPA-109) Mail Attachment does not work in HTTPS mode In internet Explorer When URL is added in trusted sites

2018-02-25 Thread Dongxu Wang (JIRA)

 [ 
https://issues.apache.org/jira/browse/HUPA-109?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Dongxu Wang reassigned HUPA-109:


Assignee: Dongxu Wang  (was: Manuel Carrasco Moñino)

> Mail Attachment does not work in HTTPS mode  In internet Explorer When URL is 
> added in trusted sites  
> --
>
> Key: HUPA-109
> URL: https://issues.apache.org/jira/browse/HUPA-109
> Project: James Hupa
>  Issue Type: Bug
>  Components: client, server
> Environment: Windows XP/7
> Internet Explorer 8/9
>Reporter: ajay kumar
>Assignee: Dongxu Wang
>Priority: Blocker
>
> Mail Attachment does not work in HTTPS mode  In internet Explorer When URL is 
> added in trusted sites  
> Steps to Reproduce:
> ***
> 1.Browse the application in HTTPS protocol in Internet Explorer only (version 
> 8,9)
> 2.Add the browsing URL in :-> Internet Options ->Security->Trusted Sites
> 3.Now send a mail with attachment to any person .
> 4.The mail is sent but attachment is not sent.
> Note: if we do not implement point :2 (above) then it works fine.
> It also works fine in other browsers except internet explorer. 
> Can you please diagnose that this can be fixed in code & what is its cause?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Assigned] (HUPA-117) The folder item should be highlighted after refreshing the page

2018-02-25 Thread Dongxu Wang (JIRA)

 [ 
https://issues.apache.org/jira/browse/HUPA-117?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Dongxu Wang reassigned HUPA-117:


Assignee: Dongxu Wang  (was: Manuel Carrasco Moñino)

> The folder item should be highlighted after refreshing the page
> ---
>
> Key: HUPA-117
> URL: https://issues.apache.org/jira/browse/HUPA-117
> Project: James Hupa
>  Issue Type: Bug
>  Components: client
>Reporter: Echo Wang
>    Assignee: Dongxu Wang
>Priority: Major
>
> The items locate in the left panel.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



Re: [Qemu-devel] [PATCH V19 1/8] V18: docs: document for add-cow file format

2013-06-02 Thread Dongxu Wang

On 2013/6/3 9:48, Fam Zheng wrote:

On Thu, 05/30 18:00, Dongxu Wang wrote:

From: Dong Xu Wang wdon...@linux.vnet.ibm.com

Document for add-cow format, the usage and spec of add-cow are
introduced.

v18-v19:
1) backing_fmt and image_fmt NUL-terminated.
2) other fix.
V17-V18:
1) remove version field.
2) header size is maximum value and cluster size value.
3) fix type.

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com


Changed git config? I suggest you could remove the old SOB line (if
respin).

Oh, yes, I changed my gitconfig file, and I did not notice these wrong 
SOB line, please ignore these boring lines. :)







[Qemu-devel] [PATCH V15 1/6] add def_value_str in QemuOptDesc struct and rewrite qemu_opts_print

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

qemu_opts_print has no user now, so can re-write the function safely.

qemu_opts_print will be used while using qemu-img create, it will
produce the same output as previous code.

The behavior of this function has changed:

1. Print every possible option, whether a value has been set or not.
2. Option descriptors may provide a default value.
3. Print to stdout instead of stderr.

Previously the behavior was to print every option that has been set.
Options that have not been set would be skipped.

v13-v14:
1) fix memory leak.
2) make opt_set do not accpet null value argument.

v12-v13
1) re-write commit message.

v11-v12
1) make def_value_str become the real default value string in opt_set
function.

v10-v11:
1) print all values that have actually been assigned while accept-any
cases.

v7-v8:
1) print elements = accept any params while opts_accepts_any() ==
true.
2) since def_print_str is the default value if an option isn't set,
so rename it to def_value_str.

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 include/qemu/option.h |  3 ++-
 util/qemu-option.c| 32 ++--
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index bdb6d21..b928ab0 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -96,6 +96,7 @@ typedef struct QemuOptDesc {
 const char *name;
 enum QemuOptType type;
 const char *help;
+const char *def_value_str;
 } QemuOptDesc;
 
 struct QemuOptsList {
@@ -152,7 +153,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
 void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
 
 typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
-int qemu_opts_print(QemuOpts *opts, void *dummy);
+int qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
*opaque,
   int abort_on_failure);
 
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 8b74bf1..84d8c8b 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -860,16 +860,36 @@ void qemu_opts_del(QemuOpts *opts)
 g_free(opts);
 }
 
-int qemu_opts_print(QemuOpts *opts, void *dummy)
+int qemu_opts_print(QemuOpts *opts)
 {
 QemuOpt *opt;
+QemuOptDesc *desc = opts-list-desc;
 
-fprintf(stderr, %s: %s:, opts-list-name,
-opts-id ? opts-id : noid);
-QTAILQ_FOREACH(opt, opts-head, next) {
-fprintf(stderr,  %s=\%s\, opt-name, opt-str);
+if (desc[0].name == NULL) {
+QTAILQ_FOREACH(opt, opts-head, next) {
+printf(%s=\%s\ , opt-name, opt-str);
+}
+return 0;
+}
+for (; desc  desc-name; desc++) {
+const char *value = desc-def_value_str;
+QemuOpt *opt;
+
+opt = qemu_opt_find(opts, desc-name);
+if (opt) {
+value = opt-str;
+}
+
+if (!value) {
+continue;
+}
+
+if (desc-type == QEMU_OPT_STRING) {
+printf(%s='%s' , desc-name, value);
+} else {
+printf(%s=%s , desc-name, value);
+}
 }
-fprintf(stderr, \n);
 return 0;
 }
 
-- 
1.7.11.7




[Qemu-devel] [PATCH V15 2/6] avoid duplication of default value in QemuOpts

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

This patch will move the default value entirely to QemuOptDesc.

When getting the value of an option that hasn't been set, and
QemuOptDesc has a default value, return that.  Else, behave as
before.

Example: qemu_opt_get_number(opts, foo, 42)

   If foo has been set in opts, return its value.

   Else, if opt's QemuOptDesc has a default value for foo, return
   that.

   Else, return 42.

   Note that the last argument is useless when QemuOptDesc has a
   default value.  Ugly.  If it bothers us, we could assert.

Example: qemu_opt_get(opts, bar)

   If bar has been set in opts, return its value.

   Else, if opt's QemuOptDesc has a default value for bar, return
   that.

   Else, return NULL.

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com

v13-v14:
1) change code style.
2) assert errors.
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 util/qemu-option.c | 66 --
 1 file changed, 49 insertions(+), 17 deletions(-)

diff --git a/util/qemu-option.c b/util/qemu-option.c
index 84d8c8b..bd2acdc 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -525,9 +525,31 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char 
*name)
 return NULL;
 }
 
+static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
+const char *name)
+{
+int i;
+
+for (i = 0; desc[i].name != NULL; i++) {
+if (strcmp(desc[i].name, name) == 0) {
+return desc[i];
+}
+}
+
+return NULL;
+}
+
 const char *qemu_opt_get(QemuOpts *opts, const char *name)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
+const QemuOptDesc *desc;
+
+if (!opt) {
+desc = find_desc_by_name(opts-list-desc, name);
+if (desc  desc-def_value_str) {
+return desc-def_value_str;
+}
+}
 return opt ? opt-str : NULL;
 }
 
@@ -546,9 +568,17 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
 bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
+const QemuOptDesc *desc;
+Error *local_err = NULL;
 
-if (opt == NULL)
+if (opt == NULL) {
+desc = find_desc_by_name(opts-list-desc, name);
+if (desc  desc-def_value_str) {
+parse_option_bool(name, desc-def_value_str, defval, local_err);
+assert(!local_err);
+}
 return defval;
+}
 assert(opt-desc  opt-desc-type == QEMU_OPT_BOOL);
 return opt-value.boolean;
 }
@@ -556,9 +586,17 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
+const QemuOptDesc *desc;
+Error *local_err = NULL;
 
-if (opt == NULL)
+if (opt == NULL) {
+desc = find_desc_by_name(opts-list-desc, name);
+if (desc  desc-def_value_str) {
+parse_option_number(name, desc-def_value_str, defval, 
local_err);
+assert(!local_err);
+}
 return defval;
+}
 assert(opt-desc  opt-desc-type == QEMU_OPT_NUMBER);
 return opt-value.uint;
 }
@@ -566,9 +604,17 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
*name, uint64_t defval)
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
+const QemuOptDesc *desc;
+Error *local_err = NULL;
 
-if (opt == NULL)
+if (opt == NULL) {
+desc = find_desc_by_name(opts-list-desc, name);
+if (desc  desc-def_value_str) {
+parse_option_size(name, desc-def_value_str, defval, local_err);
+assert(!local_err);
+}
 return defval;
+}
 assert(opt-desc  opt-desc-type == QEMU_OPT_SIZE);
 return opt-value.uint;
 }
@@ -609,20 +655,6 @@ static bool opts_accepts_any(const QemuOpts *opts)
 return opts-list-desc[0].name == NULL;
 }
 
-static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
-const char *name)
-{
-int i;
-
-for (i = 0; desc[i].name != NULL; i++) {
-if (strcmp(desc[i].name, name) == 0) {
-return desc[i];
-}
-}
-
-return NULL;
-}
-
 static void opt_set(QemuOpts *opts, const char *name, const char *value,
 bool prepend, Error **errp)
 {
-- 
1.7.11.7




[Qemu-devel] [PATCH V15 0/6] replace QEMUOptionParameter with QemuOpts parser

2013-05-30 Thread Dongxu Wang
These patches will replace QEMUOptionParameter with QemuOpts. Change logs
please go to each patch's commit message.

V14-V15:
1) Only delete enum QEMUOptionParType.

Dong Xu Wang (6):
  add def_value_str in QemuOptDesc struct and rewrite qemu_opts_print
  avoid duplication of default value in QemuOpts
  Create four QemuOptsList related functions
  Create some QemuOpts functons
  Use QemuOpts support in block layer
  remove QEMUOptionParameter related functions and struct

 block.c   | 100 
 block/cow.c   |  52 ++---
 block/gluster.c   |  37 ++-
 block/iscsi.c |  31 ++-
 block/qcow.c  |  67 +++---
 block/qcow2.c | 199 
 block/qed.c   | 108 +
 block/qed.h   |   2 +-
 block/raw-posix.c |  59 +++--
 block/raw-win32.c |  31 +--
 block/raw.c   |  30 +--
 block/rbd.c   |  62 +++--
 block/sheepdog.c  |  81 ---
 block/ssh.c   |  29 ++-
 block/vdi.c   |  70 +++---
 block/vmdk.c  | 128 ++-
 block/vpc.c   |  65 +++---
 block/vvfat.c |  11 +-
 include/block/block.h |   5 +-
 include/block/block_int.h |   6 +-
 include/qemu/option.h |  56 ++---
 qemu-img.c|  65 +++---
 util/qemu-option.c| 571 +-
 23 files changed, 904 insertions(+), 961 deletions(-)

-- 
1.7.11.7




[Qemu-devel] [PATCH V15 4/6] Create some QemuOpts functons

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

These functions will be used in next commit.

qemu_opt_get_(*)_del functions are used to make sure we
have the same behaviors as before: in block layer, after
parsing a parameter value, parameter list will delete it
to avoid parsing it twice.

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com

v13-v14:
1) rewrite commit message.
2) use def_value_str in qemu_opt_get_FOO_del() and qemu_opt_get_del().
3) delete redundant qemu_opt_del(opt).
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 include/qemu/option.h |  11 -
 util/qemu-option.c| 116 +++---
 2 files changed, 119 insertions(+), 8 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index c7a5c14..d63e447 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -108,6 +108,7 @@ struct QemuOptsList {
 };
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
+const char *qemu_opt_get_del(QemuOpts *opts, const char *name);
 /**
  * qemu_opt_has_help_opt:
  * @opts: options to search for a help request
@@ -121,13 +122,18 @@ const char *qemu_opt_get(QemuOpts *opts, const char 
*name);
  */
 bool qemu_opt_has_help_opt(QemuOpts *opts);
 bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t 
defval);
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+   uint64_t defval);
 int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
+int qemu_opt_replace_set(QemuOpts *opts, const char *name, const char *value);
 void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
   Error **errp);
 int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val);
 int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val);
+int qemu_opt_replace_set_number(QemuOpts *opts, const char *name, int64_t val);
 typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void 
*opaque);
 int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
  int abort_on_failure);
@@ -144,7 +150,10 @@ const char *qemu_opts_id(QemuOpts *opts);
 void qemu_opts_del(QemuOpts *opts);
 void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp);
 int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char 
*firstname);
-QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int 
permit_abbrev);
+int qemu_opts_do_parse_replace(QemuOpts *opts, const char *params,
+   const char *firstname);
+QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
+  int permit_abbrev);
 void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
 int permit_abbrev);
 QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
diff --git a/util/qemu-option.c b/util/qemu-option.c
index e3f482f..3251adc 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -33,6 +33,8 @@
 #include qapi/qmp/qerror.h
 #include qemu/option_int.h
 
+static void qemu_opt_del(QemuOpt *opt);
+
 /*
  * Extracts the name of an option from the parameter string (p points at the
  * first byte of the option name)
@@ -553,6 +555,24 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
 return opt ? opt-str : NULL;
 }
 
+const char *qemu_opt_get_del(QemuOpts *opts, const char *name)
+{
+QemuOpt *opt = qemu_opt_find(opts, name);
+const QemuOptDesc *desc;
+const char *str = NULL;
+
+if (!opt) {
+desc = find_desc_by_name(opts-list-desc, name);
+if (desc  desc-def_value_str) {
+str = g_strdup(desc-def_value_str);
+}
+} else {
+str = g_strdup(opt-str);
+qemu_opt_del(opt);
+}
+return str;
+}
+
 bool qemu_opt_has_help_opt(QemuOpts *opts)
 {
 QemuOpt *opt;
@@ -583,6 +603,27 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 return opt-value.boolean;
 }
 
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
+{
+QemuOpt *opt = qemu_opt_find(opts, name);
+const QemuOptDesc *desc;
+Error *local_err = NULL;
+bool ret = defval;
+
+if (opt == NULL) {
+desc = find_desc_by_name(opts-list-desc, name);
+if (desc  desc-def_value_str) {
+parse_option_bool(name, desc-def_value_str, ret, local_err);
+assert(!local_err);
+}
+return ret;
+}
+assert(opt-desc  opt-desc-type == QEMU_OPT_BOOL);
+ret = opt-value.boolean;
+qemu_opt_del(opt);
+return ret;
+}
+
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval

[Qemu-devel] [PATCH V15 3/6] Create four QemuOptsList related functions

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

This patch will create 4 functions, count_opts_list, qemu_opts_append,
qemu_opts_free and qemu_opts_print_help, they will be used in following
commits.

v12-v13:
1) simply assert that neither argument has merge_lists set.
2) drop superfluous paranthesesis around p == first.

v11-v12:
1) renmae functions.
2) fix loop styles and code styles.
3) qemu_opts_apend will not return NULL now.
4) merge_lists value is from arguments in qemu_opts_append.

v6-v7:
1) Fix typo.

v5-v6:
1) allocate enough space in append_opts_list function.

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 include/qemu/option.h |  3 ++
 util/qemu-option.c| 82 +++
 2 files changed, 85 insertions(+)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index b928ab0..c7a5c14 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -157,4 +157,7 @@ int qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
*opaque,
   int abort_on_failure);
 
+QemuOptsList *qemu_opts_append(QemuOptsList *first, QemuOptsList *second);
+void qemu_opts_free(QemuOptsList *list);
+void qemu_opts_print_help(QemuOptsList *list);
 #endif
diff --git a/util/qemu-option.c b/util/qemu-option.c
index bd2acdc..e3f482f 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1218,3 +1218,85 @@ int qemu_opts_foreach(QemuOptsList *list, 
qemu_opts_loopfunc func, void *opaque,
 loc_pop(loc);
 return rc;
 }
+
+static size_t count_opts_list(QemuOptsList *list)
+{
+size_t i = 0;
+
+for (i = 0; list  list-desc[i].name; i++) {
+;
+}
+
+return i;
+}
+
+/* Create a new QemuOptsList and make its desc to the merge of first
+ * and second. It will allocate space for one new QemuOptsList plus
+ * enough space for QemuOptDesc in first and second QemuOptsList.
+ * First argument's QemuOptDesc members take precedence over second's.
+ * The result's name and implied_opt_name are not copied from them.
+ * Both merge_lists should not be set. Both list can be NULL.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *first,
+   QemuOptsList *second)
+{
+size_t num_first_opts, num_second_opts;
+QemuOptsList *dest = NULL;
+int i = 0;
+int index = 0;
+QemuOptsList *p = first;
+
+num_first_opts = count_opts_list(first);
+num_second_opts = count_opts_list(second);
+
+dest = g_malloc0(sizeof(QemuOptsList)
++ (num_first_opts + num_second_opts + 1) * sizeof(QemuOptDesc));
+
+dest-name = append_opts_list;
+dest-implied_opt_name = NULL;
+assert((!first || !first-merge_lists)
+ (!second || !second-merge_lists));
+QTAILQ_INIT(dest-head);
+
+for (i = 0; p  p-desc[i].name; i++) {
+if (!find_desc_by_name(dest-desc, p-desc[i].name)) {
+dest-desc[index].name = g_strdup(p-desc[i].name);
+dest-desc[index].help = g_strdup(p-desc[i].help);
+dest-desc[index].type = p-desc[i].type;
+dest-desc[index].def_value_str =
+g_strdup(p-desc[i].def_value_str);
+index++;
+}
+if (p == first  p  !p-desc[i].name) {
+p = second;
+i = 0;
+}
+}
+dest-desc[index].name = NULL;
+return dest;
+}
+
+/* free a QemuOptsList, can accept NULL as arguments */
+void qemu_opts_free(QemuOptsList *list)
+{
+int i = 0;
+
+for (i = 0; list  list-desc[i].name; i++) {
+g_free((char *)list-desc[i].name);
+g_free((char *)list-desc[i].help);
+g_free((char *)list-desc[i].def_value_str);
+}
+
+g_free(list);
+}
+
+void qemu_opts_print_help(QemuOptsList *list)
+{
+int i = 0;
+printf(Supported options:\n);
+for (i = 0; list  list-desc[i].name; i++) {
+printf(%-16s %s\n, list-desc[i].name,
+list-desc[i].help ?
+list-desc[i].help : No description available);
+}
+}
-- 
1.7.11.7




[Qemu-devel] [PATCH V15 6/6] remove QEMUOptionParameter related functions and struct

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com


Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 include/qemu/option.h |  39 ---
 util/qemu-option.c| 285 --
 2 files changed, 324 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index d63e447..d2d3f16 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -31,24 +31,6 @@
 #include qapi/error.h
 #include qapi/qmp/qdict.h
 
-enum QEMUOptionParType {
-OPT_FLAG,
-OPT_NUMBER,
-OPT_SIZE,
-OPT_STRING,
-};
-
-typedef struct QEMUOptionParameter {
-const char *name;
-enum QEMUOptionParType type;
-union {
-uint64_t n;
-char* s;
-} value;
-const char *help;
-} QEMUOptionParameter;
-
-
 const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
 const char *get_opt_value(char *buf, int buf_size, const char *p);
 int get_next_param_value(char *buf, int buf_size,
@@ -58,27 +40,6 @@ int get_param_value(char *buf, int buf_size,
 int check_params(char *buf, int buf_size,
  const char * const *params, const char *str);
 
-
-/*
- * The following functions take a parameter list as input. This is a pointer to
- * the first element of a QEMUOptionParameter array which is terminated by an
- * entry with entry-name == NULL.
- */
-
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
-const char *name);
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
-const char *value);
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
-uint64_t value);
-QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
-QEMUOptionParameter *list);
-QEMUOptionParameter *parse_option_parameters(const char *param,
-QEMUOptionParameter *list, QEMUOptionParameter *dest);
-void free_option_parameters(QEMUOptionParameter *list);
-void print_option_parameters(QEMUOptionParameter *list);
-void print_option_help(QEMUOptionParameter *list);
-
 /* -- */
 
 typedef struct QemuOpt QemuOpt;
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 3251adc..e1b2a3b 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -155,22 +155,6 @@ int check_params(char *buf, int buf_size,
 return 0;
 }
 
-/*
- * Searches an option list for an option with the given name
- */
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
-const char *name)
-{
-while (list  list-name) {
-if (!strcmp(list-name, name)) {
-return list;
-}
-list++;
-}
-
-return NULL;
-}
-
 static void parse_option_bool(const char *name, const char *value, bool *ret,
   Error **errp)
 {
@@ -244,275 +228,6 @@ static void parse_option_size(const char *name, const 
char *value,
 }
 }
 
-/*
- * Sets the value of a parameter in a given option list. The parsing of the
- * value depends on the type of option:
- *
- * OPT_FLAG (uses value.n):
- *  If no value is given, the flag is set to 1.
- *  Otherwise the value must be on (set to 1) or off (set to 0)
- *
- * OPT_STRING (uses value.s):
- *  value is strdup()ed and assigned as option value
- *
- * OPT_SIZE (uses value.n):
- *  The value is converted to an integer. Suffixes for kilobytes etc. are
- *  allowed (powers of 1024).
- *
- * Returns 0 on succes, -1 in error cases
- */
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
-const char *value)
-{
-bool flag;
-Error *local_err = NULL;
-
-// Find a matching parameter
-list = get_option_parameter(list, name);
-if (list == NULL) {
-fprintf(stderr, Unknown option '%s'\n, name);
-return -1;
-}
-
-// Process parameter
-switch (list-type) {
-case OPT_FLAG:
-parse_option_bool(name, value, flag, local_err);
-if (!error_is_set(local_err)) {
-list-value.n = flag;
-}
-break;
-
-case OPT_STRING:
-if (value != NULL) {
-list-value.s = g_strdup(value);
-} else {
-fprintf(stderr, Option '%s' needs a parameter\n, name);
-return -1;
-}
-break;
-
-case OPT_SIZE:
-parse_option_size(name, value, list-value.n, local_err);
-break;
-
-default:
-fprintf(stderr, Bug: Option '%s' has an unknown type\n, name);
-return -1;
-}
-
-if (error_is_set(local_err)) {
-qerror_report_err(local_err);
-error_free(local_err);
-return -1;
-}
-
-return 0;
-}
-
-/*
- * Sets the given parameter to an integer instead of a string.
- * This function cannot be used to set string options.
- *
- * Returns 0 on success, -1 in error cases
- */
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
-uint64_t value)
-{
-// Find a matching parameter
-list

[Qemu-devel] [PATCH V19 0/8] add-cow file format

2013-05-30 Thread Dongxu Wang
It will introduce a new file format: add-cow.

The add-cow file format makes it possible to perform copy-on-write on top of
a raw disk image.  When we know that no backing file clusters remain visible
(e.g. we have streamed the entire image and copied all data from the backing
file), then it is possible to discard the add-cow file and use the raw image
file directly.

This feature adds the copy-on-write feature to raw files (which cannot support
it natively) while allowing us to get full performance again later when we no
longer need copy-on-write.

add-cow can benefit from other available functions, such as path_has_protocol
and qed_read_string, so we will make them public.

snapshot_blkdev are not supported now for add-cow. Will add it in futher 
patches.

These patches are using QemuOpts parser, former patches could be found here:
http://patchwork.ozlabs.org/patch/247508/


v18-v19:
1) support parallel aio write.
2) fix flush method.
3) other small fix.
v17 - v18:
1) remove version field.
2) header size is maximum value and cluster size value.
3) fix type.
4) move struct to source file.
5) cluster_size-table_size.
6) use error_report, not fprintf.
7) remove version field from header.
8) header_size is MAX(cluster_size, 4096).
9) introduce s-cluster_sectors.
10) use BLKDBG_L2_LOAD/UPDATE.
11) add 037 and 038 tests.

v16-v17):
1) Use stringify.

v15-v16):
1) Rebased on QEMU upstream source tree.
2) Judge if opts is null in add_cow_create function.

v14-v15:
1) Fix typo and make some sentences more readable in docs.
2) Introduce STRINGIZER macro.

v13-v14:
1) Make some sentences more clear in docs.
2) Make MAGIC from 8 bytes to 4 bytes.
3) Fix some bugs.

v12-v13:
1) Use QemuOpts, not QEMUOptionParameter
2) cluster_size configuable
3) Refactor block-cache.c
4) Correct qemu-iotests script.
5) Other bug fix.

v11-v12:
1) Removed un-used feature bit.
2) Share cache code with qcow2.c.
3) Remove snapshot_blkdev support, will add it in another patch.
5) COW Bitmap field in add-cow file will be multiple of 65536.
6) fix grammer and typo.

Dong Xu Wang (8):
  V18: docs: document for add-cow file format
  make path_has_protocol non static
  qed_read_string to bdrv_read_string
  rename qcow2-cache.c to block-cache.c
  Make block-cache.c be common interface
  add debug event for add-cow
  add-cow file format core code.
  qemu-iotests: add add-cow iotests support

 block.c  |  29 +-
 block/Makefile.objs  |   4 +-
 block/add-cow.c  | 812 +++
 block/blkdebug.c |   3 +
 block/block-cache.c  | 342 ++
 block/qcow2-cache.c  | 323 -
 block/qcow2-cluster.c|  52 +--
 block/qcow2-refcount.c   |  62 ++--
 block/qcow2.c|  21 +-
 block/qcow2.h|  24 +-
 block/qed.c  |  34 +-
 docs/specs/add-cow.txt   | 172 +
 include/block/block-cache.h  |  59 
 include/block/block.h|   6 +
 include/block/block_int.h|   2 +
 tests/qemu-iotests/017   |   2 +-
 tests/qemu-iotests/020   |   2 +-
 tests/qemu-iotests/037   |   2 +-
 tests/qemu-iotests/038   |   2 +-
 tests/qemu-iotests/common|   6 +
 tests/qemu-iotests/common.rc |  15 +-
 trace-events |  13 +-
 22 files changed, 1536 insertions(+), 451 deletions(-)
 create mode 100644 block/add-cow.c
 create mode 100644 block/block-cache.c
 delete mode 100644 block/qcow2-cache.c
 create mode 100644 docs/specs/add-cow.txt
 create mode 100644 include/block/block-cache.h

-- 
1.7.11.7




[Qemu-devel] [PATCH V19 1/8] V18: docs: document for add-cow file format

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

Document for add-cow format, the usage and spec of add-cow are
introduced.

v18-v19:
1) backing_fmt and image_fmt NUL-terminated.
2) other fix.
V17-V18:
1) remove version field.
2) header size is maximum value and cluster size value.
3) fix type.

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 docs/specs/add-cow.txt | 172 +
 1 file changed, 172 insertions(+)
 create mode 100644 docs/specs/add-cow.txt

diff --git a/docs/specs/add-cow.txt b/docs/specs/add-cow.txt
new file mode 100644
index 000..fba74dd
--- /dev/null
+++ b/docs/specs/add-cow.txt
@@ -0,0 +1,172 @@
+== General ==
+
+The raw file format does not support backing files or copy on write
+feature. The add-cow image format makes it possible to use backing
+files with an image by keeping a separate .add-cow metadata file.
+Once all clusters have been written into the image it is safe to
+discard the .add-cow and backing files, then we can use the image
+directly.
+
+An example usage of add-cow would look like:
+(ubuntu.img is a disk image which has an installed OS.)
+1)  Create an image, such as raw format, with the same size of
+ubuntu.img:
+qemu-img create -f raw test.raw 8G
+2)  Create an add-cow image which will store dirty bitmap
+qemu-img create -f add-cow test.add-cow \
+-o backing_file=ubuntu.img,image_file=test.raw
+3)  Run qemu with add-cow image
+qemu -drive if=virtio,file=test.add-cow
+
+test.raw may be larger than ubuntu.img, in that case, the size of
+test.add-cow will be calculated from the size of test.raw.
+
+image_fmt can be omitted, in that case image_fmt is assumed to be
+raw. backing_fmt can also be omitted, add-cow should do a probe
+operation and determine what the backing file's format is. It is
+recommended to always specify the format for any raw file, because
+probing a raw file is a security hole.
+
+=Specification=
+
+The file format looks like this:
+
+ +---+---+
+ | Header|   COW bitmap  |
+ +---+---+
+
+All numbers in add-cow are stored in Little Endian byte order.
+
+== Header ==
+
+The Header is included in the first bytes:
+(HEADER_SIZE is defined in 40-43 bytes.)
+Byte0  -  3:magic
+add-cow magic string (ACOW). It is coded in
+free-form ASCII.
+
+4  -  7:backing file name offset
+Offset in the add-cow file at which the backing
+file name is stored (NB: The string is NOT
+NUL-terminated).
+If backing file name does NOT exist, this field
+will be 0. Must be between 76 and [HEADER_SIZE
+- 2](a file name must be at least 1 byte).
+
+8  - 11:backing file name size
+Length of the backing file name in bytes. It
+will be 0 if the backing file name offset is
+0. If backing file name offset is non-zero,
+then it must be non-zero. Must be less than
+[HEADER_SIZE - 76] to fit in the reserved
+part of the header. Backing file name offset
++ size must be no more than HEADER_SIZE.
+
+12 - 15:image file name offset
+Offset in the add-cow file at which the image
+file name is stored (NB: The string is NOT
+NUL-terminated). It must be between 76 and
+[HEADER_SIZE - 2]. Image file name size + offset
+must be no more than HEADER_SIZE.
+
+16 - 19:image file name size
+Length of the image file name in bytes.
+Must be less than [HEADER_SIZE - 76] to fit in
+the reserved part of the header.
+
+20 - 23:cluster bits
+Number of bits that are used for addressing an
+offset within a cluster (1  cluster_bits is
+the cluster size). Must not be less than 12
+(i.e. 4096 byte clusters).
+
+Note: qemu as of today has an implementation
+limit of 2 MB as the maximum cluster size and
+won't be able to open images with larger cluster
+sizes.
+
+24 - 31:features
+Bitmask of features. If a feature bit is set
+but not recognized, the opening add-cow file must
+fail.  No features bits are currently defined

[Qemu-devel] [PATCH V19 4/8] rename qcow2-cache.c to block-cache.c

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

Block layer will use qcow2-cache as common cache code, so rename
it to block-cache.c.

v18-v19:
1) only rename, did not touch other code.

Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 block/Makefile.objs|   3 +-
 block/block-cache.c| 323 +
 block/qcow2-cache.c| 323 -
 block/qcow2-cluster.c  |  48 
 block/qcow2-refcount.c |  42 +++
 block/qcow2.c  |  18 +--
 block/qcow2.h  |  28 ++---
 trace-events   |  12 +-
 8 files changed, 399 insertions(+), 398 deletions(-)
 create mode 100644 block/block-cache.c
 delete mode 100644 block/qcow2-cache.c

diff --git a/block/Makefile.objs b/block/Makefile.objs
index 5f0358a..16e574a 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -1,5 +1,6 @@
 block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o 
vvfat.o
-block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
qcow2-cache.o
+block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o
+block-obj-y += block-cache.o
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
 block-obj-y += vhdx.o
diff --git a/block/block-cache.c b/block/block-cache.c
new file mode 100644
index 000..bc057a8
--- /dev/null
+++ b/block/block-cache.c
@@ -0,0 +1,323 @@
+/*
+ * L2/refcount table cache for the QCOW2 format
+ *
+ * Copyright (c) 2010 Kevin Wolf kw...@redhat.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include block/block_int.h
+#include qemu-common.h
+#include qcow2.h
+#include trace.h
+
+typedef struct BlockCachedTable {
+void*   table;
+int64_t offset;
+booldirty;
+int cache_hits;
+int ref;
+} BlockCachedTable;
+
+struct BlockCache {
+BlockCachedTable*   entries;
+struct BlockCache*  depends;
+int size;
+booldepends_on_flush;
+};
+
+BlockCache *block_cache_create(BlockDriverState *bs, int num_tables)
+{
+BDRVQcowState *s = bs-opaque;
+BlockCache *c;
+int i;
+
+c = g_malloc0(sizeof(*c));
+c-size = num_tables;
+c-entries = g_malloc0(sizeof(*c-entries) * num_tables);
+
+for (i = 0; i  c-size; i++) {
+c-entries[i].table = qemu_blockalign(bs, s-cluster_size);
+}
+
+return c;
+}
+
+int block_cache_destroy(BlockDriverState* bs, BlockCache *c)
+{
+int i;
+
+for (i = 0; i  c-size; i++) {
+assert(c-entries[i].ref == 0);
+qemu_vfree(c-entries[i].table);
+}
+
+g_free(c-entries);
+g_free(c);
+
+return 0;
+}
+
+static int block_cache_flush_dependency(BlockDriverState *bs, BlockCache *c)
+{
+int ret;
+
+ret = block_cache_flush(bs, c-depends);
+if (ret  0) {
+return ret;
+}
+
+c-depends = NULL;
+c-depends_on_flush = false;
+
+return 0;
+}
+
+static int block_cache_entry_flush(BlockDriverState *bs, BlockCache *c, int i)
+{
+BDRVQcowState *s = bs-opaque;
+int ret = 0;
+
+if (!c-entries[i].dirty || !c-entries[i].offset) {
+return 0;
+}
+
+trace_block_cache_entry_flush(qemu_coroutine_self(),
+  c == s-l2_table_cache, i);
+
+if (c-depends) {
+ret = block_cache_flush_dependency(bs, c);
+} else if (c-depends_on_flush) {
+ret = bdrv_flush(bs-file);
+if (ret = 0) {
+c-depends_on_flush = false;
+}
+}
+
+if (ret  0) {
+return ret;
+}
+
+if (c == s-refcount_block_cache) {
+BLKDBG_EVENT(bs-file, BLKDBG_REFBLOCK_UPDATE_PART);
+} else if (c == s-l2_table_cache) {
+BLKDBG_EVENT(bs-file, BLKDBG_L2_UPDATE);
+}
+
+ret = bdrv_pwrite(bs-file, c-entries[i].offset, c-entries[i].table,
+s-cluster_size);
+if (ret  0) {
+return

[Qemu-devel] [PATCH V19 3/8] qed_read_string to bdrv_read_string

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

Make qed_read_string function to a common interface, so move it to
block.c.

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 block.c   | 27 +++
 block/qed.c   | 34 --
 include/block/block.h |  2 ++
 3 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/block.c b/block.c
index 5135044..65c5e76 100644
--- a/block.c
+++ b/block.c
@@ -210,6 +210,33 @@ int path_has_protocol(const char *path)
 return *p == ':';
 }
 
+/**
+ * Read a string of known length from the image file
+ *
+ * @bs: Image file
+ * @offset: File offset to start of string, in bytes
+ * @n:  String length in bytes
+ * @buf:Destination buffer
+ * @buflen: Destination buffer length in bytes
+ * @ret:0 on success, -errno on failure
+ *
+ * The string is NUL-terminated.
+ */
+int bdrv_read_string(BlockDriverState *bs, uint64_t offset, size_t n,
+ char *buf, size_t buflen)
+{
+int ret;
+if (n = buflen) {
+return -EINVAL;
+}
+ret = bdrv_pread(bs, offset, buf, n);
+if (ret  0) {
+return ret;
+}
+buf[n] = '\0';
+return 0;
+}
+
 int path_is_absolute(const char *path)
 {
 #ifdef _WIN32
diff --git a/block/qed.c b/block/qed.c
index 88daf22..077da76 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -217,33 +217,6 @@ static bool qed_is_image_size_valid(uint64_t image_size, 
uint32_t cluster_size,
 }
 
 /**
- * Read a string of known length from the image file
- *
- * @file:   Image file
- * @offset: File offset to start of string, in bytes
- * @n:  String length in bytes
- * @buf:Destination buffer
- * @buflen: Destination buffer length in bytes
- * @ret:0 on success, -errno on failure
- *
- * The string is NUL-terminated.
- */
-static int qed_read_string(BlockDriverState *file, uint64_t offset, size_t n,
-   char *buf, size_t buflen)
-{
-int ret;
-if (n = buflen) {
-return -EINVAL;
-}
-ret = bdrv_pread(file, offset, buf, n);
-if (ret  0) {
-return ret;
-}
-buf[n] = '\0';
-return 0;
-}
-
-/**
  * Allocate new clusters
  *
  * @s:  QED state
@@ -437,9 +410,10 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict 
*options, int flags)
 return -EINVAL;
 }
 
-ret = qed_read_string(bs-file, s-header.backing_filename_offset,
-  s-header.backing_filename_size, 
bs-backing_file,
-  sizeof(bs-backing_file));
+ret = bdrv_read_string(bs-file, s-header.backing_filename_offset,
+   s-header.backing_filename_size,
+   bs-backing_file,
+   sizeof(bs-backing_file));
 if (ret  0) {
 return ret;
 }
diff --git a/include/block/block.h b/include/block/block.h
index fd776a1..2989da6 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -175,6 +175,8 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
 const void *buf, int count);
 int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
 int nb_sectors, QEMUIOVector *qiov);
+int bdrv_read_string(BlockDriverState *bs, uint64_t offset, size_t n,
+ char *buf, size_t buflen);
 int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
 int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
 int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
-- 
1.7.11.7




[Qemu-devel] [PATCH V19 2/8] make path_has_protocol non static

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

We will use path_has_protocol outside block.c, so just make it public.

Reviewed-by: Michael Roth mdr...@linux.vnet.ibm.com
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 block.c   | 2 +-
 include/block/block.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/block.c b/block.c
index 710362f..5135044 100644
--- a/block.c
+++ b/block.c
@@ -193,7 +193,7 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs,
 }
 
 /* check if the path starts with protocol: */
-static int path_has_protocol(const char *path)
+int path_has_protocol(const char *path)
 {
 const char *p;
 
diff --git a/include/block/block.h b/include/block/block.h
index 90f95ef..fd776a1 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -345,6 +345,7 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, 
QEMUSnapshotInfo *sn);
 
 char *get_human_readable_size(char *buf, int buf_size, int64_t size);
 int path_is_absolute(const char *path);
+int path_has_protocol(const char *path);
 void path_combine(char *dest, int dest_size,
   const char *base_path,
   const char *filename);
-- 
1.7.11.7




[Qemu-devel] [PATCH V19 8/8] qemu-iotests: add add-cow iotests support

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

This patch will use qemu-iotests to test add-cow file format.

v17-v18:
1) add 037 and 038 tests.

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 tests/qemu-iotests/017   |  2 +-
 tests/qemu-iotests/020   |  2 +-
 tests/qemu-iotests/037   |  2 +-
 tests/qemu-iotests/038   |  2 +-
 tests/qemu-iotests/common|  6 ++
 tests/qemu-iotests/common.rc | 15 ++-
 6 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017
index 45f2c0b..ae0e627 100755
--- a/tests/qemu-iotests/017
+++ b/tests/qemu-iotests/017
@@ -40,7 +40,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files
-_supported_fmt qcow qcow2 vmdk qed
+_supported_fmt qcow qcow2 vmdk qed add-cow
 _supported_proto generic
 _supported_os Linux
 
diff --git a/tests/qemu-iotests/020 b/tests/qemu-iotests/020
index 2fb0ff8..3dbb495 100755
--- a/tests/qemu-iotests/020
+++ b/tests/qemu-iotests/020
@@ -42,7 +42,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files
-_supported_fmt qcow qcow2 vmdk qed
+_supported_fmt qcow qcow2 vmdk qed add-cow
 _supported_proto generic
 _supported_os Linux
 
diff --git a/tests/qemu-iotests/037 b/tests/qemu-iotests/037
index c11460b..683e73d 100755
--- a/tests/qemu-iotests/037
+++ b/tests/qemu-iotests/037
@@ -38,7 +38,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 . ./common.rc
 . ./common.filter
 
-_supported_fmt qcow qcow2 vmdk qed
+_supported_fmt qcow qcow2 vmdk qed add-cow
 _supported_proto generic
 _supported_os Linux
 
diff --git a/tests/qemu-iotests/038 b/tests/qemu-iotests/038
index 36125ea..10bacfb 100755
--- a/tests/qemu-iotests/038
+++ b/tests/qemu-iotests/038
@@ -38,7 +38,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 . ./common.rc
 . ./common.filter
 
-_supported_fmt qcow2 qed
+_supported_fmt qcow2 qed add-cow
 _supported_proto generic
 _supported_os Linux
 
diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common
index 6826ea7..5110fc1 100644
--- a/tests/qemu-iotests/common
+++ b/tests/qemu-iotests/common
@@ -128,6 +128,7 @@ common options
 check options
 -rawtest raw (default)
 -cowtest cow
+-add-cowtest add-cow
 -qcow   test qcow
 -qcow2  test qcow2
 -qedtest qed
@@ -165,6 +166,11 @@ testlist options
xpand=false
;;
 
+-add-cow)
+IMGFMT=add-cow
+xpand=false
+;;
+
-qcow)
IMGFMT=qcow
xpand=false
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index e9ba358..b203f04 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -110,6 +110,16 @@ _make_test_img()
 fi
 if [ \( $IMGFMT = qcow2 -o $IMGFMT = qed \) -a -n $CLUSTER_SIZE 
]; then
 optstr=$(_optstr_add $optstr cluster_size=$CLUSTER_SIZE)
+elif [ $IMGFMT = add-cow ]; then
+local IMG=$TEST_IMG.raw
+if [ $1 = -b ]; then
+IMG=$IMG.b
+$QEMU_IMG create -f raw $IMG $image_size/dev/null
+extra_img_options=-o image_file=$IMG $extra_img_options
+else
+$QEMU_IMG create -f raw $IMG $image_size/dev/null
+extra_img_options=-o image_file=$IMG
+fi
 fi
 
 if [ -n $optstr ]; then
@@ -130,7 +140,8 @@ _make_test_img()
 -e s# zeroed_grain=\\(on\\|off\\)##g \
 -e s# subformat='[^']*'##g \
 -e s# adapter_type='[^']*'##g \
--e s# lazy_refcounts=\\(on\\|off\\)##g
+-e s# lazy_refcounts=\\(on\\|off\\)##g \
+-e s# image_file='[^']*'##g
 
 # Start an NBD server on the image file, which is what we'll be talking to
 if [ $IMGPROTO = nbd ]; then
@@ -152,6 +163,8 @@ _cleanup_test_img()
 rm -f $TEST_DIR/t.$IMGFMT
 rm -f $TEST_DIR/t.$IMGFMT.orig
 rm -f $TEST_DIR/t.$IMGFMT.base
+rm -f $TEST_DIR/t.$IMGFMT.raw
+rm -f $TEST_DIR/t.$IMGFMT.raw.b
 ;;
 
 rbd)
-- 
1.7.11.7




[Qemu-devel] [PATCH V19 7/8] add-cow file format core code.

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

add-cow file format core code. It use block-cache.c as cache code.
It lacks of snapshot_blkdev support.

v18-v19:
1) add aio parallel write support.
2) fix flush method.

v17-v18:
1) use error_report, not fprintf.
2) remove version field from header.
3) header_size is MAX(cluster_size, 4096).
4) introduce s-cluster_sectors.
5) use BLKDBG_L2_LOAD/UPDATE.

v16-v17:
1) Use stringify.

v15-v16:
1) Judge if opts is null in add_cow_create function.

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com

Conflicts:
block/block-cache.c
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 block/Makefile.objs |   1 +
 block/add-cow.c | 812 
 block/block-cache.c |  16 +-
 include/block/block-cache.h |   4 +
 include/block/block_int.h   |   2 +
 5 files changed, 831 insertions(+), 4 deletions(-)
 create mode 100644 block/add-cow.c

diff --git a/block/Makefile.objs b/block/Makefile.objs
index 16e574a..f666a7a 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -1,6 +1,7 @@
 block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o 
vvfat.o
 block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o
 block-obj-y += block-cache.o
+block-obj-y += add-cow.o
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
 block-obj-y += vhdx.o
diff --git a/block/add-cow.c b/block/add-cow.c
new file mode 100644
index 000..290da3c
--- /dev/null
+++ b/block/add-cow.c
@@ -0,0 +1,812 @@
+/*
+ * QEMU ADD-COW Disk Format
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Dong Xu Wang wdon...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include qemu-common.h
+#include block/block_int.h
+#include qemu/module.h
+#include block/block-cache.h
+
+#define ACOW_CLUSTER_SIZE 65536
+
+typedef struct AddCowMeta
+{
+uint64_t start_sector;
+int remaining_sectors;
+CoQueue dependent_requests;
+struct AddCowMeta *next;
+
+QLIST_ENTRY(AddCowMeta) next_in_flight;
+} AddCowMeta;
+
+enum {
+/* compat_features bit */
+ACOW_F_ALL_ALLOCATED= 0X01,
+
+/* none feature bit used now */
+ACOW_FEATURE_MASK   = 0,
+
+ACOW_MAGIC  = 'A' | 'C'  8 | 'O'  16 | 'W'  24,
+ACOW_CACHE_SIZE = 16,
+DEFAULT_HEADER_SIZE = 4096,
+MIN_CLUSTER_BITS= 12,
+MAX_CLUSTER_BITS= 21,
+};
+
+typedef struct AddCowHeader {
+uint32_tmagic;
+
+uint32_tbacking_offset;
+uint32_tbacking_size;
+uint32_timage_offset;
+uint32_timage_size;
+
+uint32_tcluster_bits;
+uint64_tfeatures;
+uint64_tcompat_features;
+uint32_theader_size;
+
+charbacking_fmt[16];
+charimage_fmt[16];
+} QEMU_PACKED AddCowHeader;
+
+typedef struct BDRVAddCowState {
+BlockDriverState*image_hd;
+CoMutex lock;
+int cluster_size;
+int cluster_sectors;
+BlockCache  *bitmap_cache;
+uint64_tbitmap_size;
+AddCowHeaderheader;
+charbacking_fmt[16];
+charimage_fmt[16];
+BlockCache  *image_hd_cache;
+QLIST_HEAD(AddCowAlloc, AddCowMeta) cluster_allocs;
+} BDRVAddCowState;
+
+/* Convert sector_num to offset in bitmap */
+static inline int64_t offset_in_bitmap(int64_t sector_num,
+   int64_t cluster_sectors)
+{
+int64_t cluster_num = sector_num / cluster_sectors;
+return cluster_num / 8;
+}
+
+static inline bool is_cluster_head(int64_t sector_num,
+   int64_t cluster_sectors)
+{
+return sector_num % cluster_sectors == 0;
+}
+
+static inline bool is_cluster_tail(int64_t sector_num,
+   int64_t cluster_sectors)
+{
+return (sector_num + 1) % cluster_sectors == 0;
+}
+
+static void add_cow_header_le_to_cpu(const AddCowHeader *le, AddCowHeader *cpu)
+{
+cpu-magic  = le32_to_cpu(le-magic);
+
+cpu-backing_offset = le32_to_cpu(le-backing_offset);
+cpu-backing_size   = le32_to_cpu(le-backing_size);
+cpu-image_offset   = le32_to_cpu(le-image_offset);
+cpu-image_size = le32_to_cpu(le-image_size);
+
+cpu-cluster_bits   = le32_to_cpu(le-cluster_bits);
+cpu-features   = le64_to_cpu(le-features);
+cpu-compat_features= le64_to_cpu(le-compat_features);
+cpu-header_size= le32_to_cpu(le-header_size);
+
+memcpy(cpu-backing_fmt, le-backing_fmt, sizeof(cpu-backing_fmt));
+memcpy(cpu-image_fmt, le-image_fmt, sizeof(cpu-image_fmt));
+}
+
+static void add_cow_header_cpu_to_le(const AddCowHeader *cpu, AddCowHeader *le)
+{
+le-magic

[Qemu-devel] [PATCH V19 5/8] Make block-cache.c be common interface

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

To use block-cache.c be common cache interface, we need to add
some parameter to identify cache's type.

Define a struct named BlockTableType, pass BlockTableType and
table size parameters to block cache initialization function.

v17-v18:
1) move struct to source file.
2) cluster_size-table_size.

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 block/block-cache.c | 75 ++---
 block/qcow2-cluster.c   | 30 +-
 block/qcow2-refcount.c  | 30 +-
 block/qcow2.c   |  7 +++--
 block/qcow2.h   | 24 ++-
 include/block/block-cache.h | 55 +
 trace-events|  1 +
 7 files changed, 139 insertions(+), 83 deletions(-)
 create mode 100644 include/block/block-cache.h

diff --git a/block/block-cache.c b/block/block-cache.c
index bc057a8..f5d75d1 100644
--- a/block/block-cache.c
+++ b/block/block-cache.c
@@ -1,4 +1,8 @@
 /*
+ * QEMU Block Layer Cache
+ *
+ * This file is based on qcow2-cache.c, see its copyrights below:
+ *
  * L2/refcount table cache for the QCOW2 format
  *
  * Copyright (c) 2010 Kevin Wolf kw...@redhat.com
@@ -24,11 +28,11 @@
 
 #include block/block_int.h
 #include qemu-common.h
-#include qcow2.h
 #include trace.h
+#include block/block-cache.h
 
 typedef struct BlockCachedTable {
-void*   table;
+void*table;
 int64_t offset;
 booldirty;
 int cache_hits;
@@ -36,30 +40,34 @@ typedef struct BlockCachedTable {
 } BlockCachedTable;
 
 struct BlockCache {
-BlockCachedTable*   entries;
-struct BlockCache*  depends;
-int size;
-booldepends_on_flush;
+BlockCachedTable*entries;
+struct BlockCache   *depends;
+int size;
+size_t  table_size;
+BlockTableType  table_type;
+booldepends_on_flush;
 };
 
-BlockCache *block_cache_create(BlockDriverState *bs, int num_tables)
+BlockCache *block_cache_create(BlockDriverState *bs, int num_tables,
+   size_t table_size, BlockTableType type)
 {
-BDRVQcowState *s = bs-opaque;
 BlockCache *c;
 int i;
 
 c = g_malloc0(sizeof(*c));
 c-size = num_tables;
 c-entries = g_malloc0(sizeof(*c-entries) * num_tables);
+c-table_type = type;
+c-table_size = table_size;
 
 for (i = 0; i  c-size; i++) {
-c-entries[i].table = qemu_blockalign(bs, s-cluster_size);
+c-entries[i].table = qemu_blockalign(bs, table_size);
 }
 
 return c;
 }
 
-int block_cache_destroy(BlockDriverState* bs, BlockCache *c)
+int block_cache_destroy(BlockDriverState *bs, BlockCache *c)
 {
 int i;
 
@@ -91,15 +99,13 @@ static int block_cache_flush_dependency(BlockDriverState 
*bs, BlockCache *c)
 
 static int block_cache_entry_flush(BlockDriverState *bs, BlockCache *c, int i)
 {
-BDRVQcowState *s = bs-opaque;
 int ret = 0;
 
 if (!c-entries[i].dirty || !c-entries[i].offset) {
 return 0;
 }
 
-trace_block_cache_entry_flush(qemu_coroutine_self(),
-  c == s-l2_table_cache, i);
+trace_block_cache_entry_flush(qemu_coroutine_self(), c-table_type, i);
 
 if (c-depends) {
 ret = block_cache_flush_dependency(bs, c);
@@ -114,14 +120,16 @@ static int block_cache_entry_flush(BlockDriverState *bs, 
BlockCache *c, int i)
 return ret;
 }
 
-if (c == s-refcount_block_cache) {
+if (c-table_type == BLOCK_TABLE_REF) {
 BLKDBG_EVENT(bs-file, BLKDBG_REFBLOCK_UPDATE_PART);
-} else if (c == s-l2_table_cache) {
+} else if (c-table_type == BLOCK_TABLE_L2) {
 BLKDBG_EVENT(bs-file, BLKDBG_L2_UPDATE);
+} else if (c-table_type == BLOCK_TABLE_BITMAP) {
+BLKDBG_EVENT(bs-file, BLKDBG_COW_WRITE);
 }
 
-ret = bdrv_pwrite(bs-file, c-entries[i].offset, c-entries[i].table,
-s-cluster_size);
+ret = bdrv_pwrite(bs-file, c-entries[i].offset,
+  c-entries[i].table, c-table_size);
 if (ret  0) {
 return ret;
 }
@@ -133,12 +141,11 @@ static int block_cache_entry_flush(BlockDriverState *bs, 
BlockCache *c, int i)
 
 int block_cache_flush(BlockDriverState *bs, BlockCache *c)
 {
-BDRVQcowState *s = bs-opaque;
 int result = 0;
 int ret;
 int i;
 
-trace_block_cache_flush(qemu_coroutine_self(), c == s-l2_table_cache);
+trace_block_cache_flush(qemu_coroutine_self(), c-table_type);
 
 for (i = 0; i  c-size; i++) {
 ret = block_cache_entry_flush(bs, c, i);
@@ -157,8 +164,9 @@ int block_cache_flush(BlockDriverState *bs, BlockCache *c)
 return result;
 }
 
-int block_cache_set_dependency(BlockDriverState *bs, BlockCache *c,
-BlockCache *dependency)
+int block_cache_set_dependency(BlockDriverState *bs

[Qemu-devel] [RFC] Check backing_file chain's loop

2013-05-30 Thread Dongxu Wang

Hi,

Now block layer does not check whether backing_file chain can be a 
circle, do you think it is necessary to do a check?


For example,  1.qcow2's backing_file is 2.qcow2 and 2.qcow2's 
backing_file is 1.qcow2, then any IO operation will be a fault.


If necessary, I will post a patch to fix.

[$] qemu-img create -f qcow2 1.qcow2
qemu-img: Image creation needs a size parameter
[$] qemu-img create -f qcow2 1.qcow2 8M
Formatting '1.qcow2', fmt=qcow2 size=8388608 encryption=off 
cluster_size=65536 lazy_refcounts=off

[$] qemu-img create -f qcow2 2.qcow2 -o backing_file=1.qcow2
Formatting '2.qcow2', fmt=qcow2 size=8388608 backing_file='1.qcow2' 
encryption=off cluster_size=65536 lazy_refcounts=off

[$] qemu-img create -f qcow2 1.qcow2 -o backing_file=2.qcow2
Formatting '1.qcow2', fmt=qcow2 size=8388608 backing_file='2.qcow2' 
encryption=off cluster_size=65536 lazy_refcounts=off

[$] qemu-io -c read -v 0 512 1.qcow2
^CSegmentation fault (core dumped)



Thanks.




[Qemu-devel] [PATCH V19 6/8] add debug event for add-cow

2013-05-30 Thread Dongxu Wang
From: Dong Xu Wang wdon...@linux.vnet.ibm.com

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com
---
 block/blkdebug.c  | 3 +++
 block/block-cache.c   | 4 ++--
 include/block/block.h | 3 +++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/block/blkdebug.c b/block/blkdebug.c
index 71f99e4..2bd6a53 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -182,6 +182,9 @@ static const char *event_names[BLKDBG_EVENT_MAX] = {
 [BLKDBG_CLUSTER_ALLOC]  = cluster_alloc,
 [BLKDBG_CLUSTER_ALLOC_BYTES]= cluster_alloc_bytes,
 [BLKDBG_CLUSTER_FREE]   = cluster_free,
+
+[BLKDBG_ADDCOW_READ]= add_cow_read,
+[BLKDBG_ADDCOW_WRITE]   = add_cow_write,
 };
 
 static int get_event_by_name(const char *name, BlkDebugEvent *event)
diff --git a/block/block-cache.c b/block/block-cache.c
index f5d75d1..454269c 100644
--- a/block/block-cache.c
+++ b/block/block-cache.c
@@ -125,7 +125,7 @@ static int block_cache_entry_flush(BlockDriverState *bs, 
BlockCache *c, int i)
 } else if (c-table_type == BLOCK_TABLE_L2) {
 BLKDBG_EVENT(bs-file, BLKDBG_L2_UPDATE);
 } else if (c-table_type == BLOCK_TABLE_BITMAP) {
-BLKDBG_EVENT(bs-file, BLKDBG_COW_WRITE);
+BLKDBG_EVENT(bs-file, BLKDBG_ADDCOW_WRITE);
 }
 
 ret = bdrv_pwrite(bs-file, c-entries[i].offset,
@@ -260,7 +260,7 @@ static int block_cache_do_get(BlockDriverState *bs, 
BlockCache *c,
 if (c-table_type == BLOCK_TABLE_L2) {
 BLKDBG_EVENT(bs-file, BLKDBG_L2_LOAD);
 } else if (c-table_type == BLOCK_TABLE_BITMAP) {
-BLKDBG_EVENT(bs-file, BLKDBG_COW_READ);
+BLKDBG_EVENT(bs-file, BLKDBG_ADDCOW_READ);
 }
 
 ret = bdrv_pread(bs-file, offset, c-entries[i].table,
diff --git a/include/block/block.h b/include/block/block.h
index 2989da6..3573e3e 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -451,6 +451,9 @@ typedef enum {
 BLKDBG_CLUSTER_ALLOC_BYTES,
 BLKDBG_CLUSTER_FREE,
 
+BLKDBG_ADDCOW_READ,
+BLKDBG_ADDCOW_WRITE,
+
 BLKDBG_EVENT_MAX,
 } BlkDebugEvent;
 
-- 
1.7.11.7




Re: [Qemu-devel] [RFC] Check backing_file chain's loop

2013-05-30 Thread Dongxu Wang

On 2013/5/30 20:48, Stefan Hajnoczi wrote:

hain 1.qcow2' don't crash.

qemu-img info --backing-chain detects cycles and returns an error, see
the hash table in collect_image_info_list().

We should protect bdrv_open() too.


Okay, will send a patch.

Stefan







Re: [Qemu-devel] [PATCH V15 1/6] add def_value_str in QemuOptDesc struct and rewrite qemu_opts_print

2013-05-30 Thread Dongxu Wang

On 2013/5/31 5:22, Eric Blake wrote:

On 05/30/2013 03:55 AM, Dongxu Wang wrote:

From: Dong Xu Wang wdon...@linux.vnet.ibm.com

qemu_opts_print has no user now, so can re-write the function safely.

qemu_opts_print will be used while using qemu-img create, it will
produce the same output as previous code.

The behavior of this function has changed:

1. Print every possible option, whether a value has been set or not.
2. Option descriptors may provide a default value.
3. Print to stdout instead of stderr.

Previously the behavior was to print every option that has been set.
Options that have not been set would be skipped.


Up to here is fine.



v13-v14:
1) fix memory leak.
2) make opt_set do not accpet null value argument.

v12-v13
1) re-write commit message.

v11-v12
1) make def_value_str become the real default value string in opt_set
function.

v10-v11:
1) print all values that have actually been assigned while accept-any
cases.

v7-v8:
1) print elements = accept any params while opts_accepts_any() ==
true.
2) since def_print_str is the default value if an option isn't set,
so rename it to def_value_str.


However, this chunk should be moved to appear after the '---' separator;
it's useful during review, but does not need to be part of qemu.git.


Okay.


Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com


And this looks fishy, having two S-o-B with slightly different spellings
of your name.  Pick one and stick with it.


Ah.. sorry, my mistake..

---


Here is where patch changelogs go.  For more hints, see
http://wiki.qemu.org/Contribute/SubmitAPatch


  include/qemu/option.h |  3 ++-
  util/qemu-option.c| 32 ++--
  2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index bdb6d21..b928ab0 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -96,6 +96,7 @@ typedef struct QemuOptDesc {
  const char *name;
  enum QemuOptType type;
  const char *help;
+const char *def_value_str;
  } QemuOptDesc;


Now that we have the 'query-command-line-options' QMP command, I think
it's worth expanding that command to expose the default value of an
option, when one is given.  It's probably content for a separate patch
(util/qemu-config.c:query_option_descs() and qapi-schema.json), but
still belongs as part of this series.

Reviewed-by: Eric Blake ebl...@redhat.com






Re: [Qemu-devel] [PATCH V15 3/6] Create four QemuOptsList related functions

2013-05-30 Thread Dongxu Wang

On 2013/5/31 5:43, Eric Blake wrote:

On 05/30/2013 03:55 AM, Dongxu Wang wrote:

From: Dong Xu Wang wdon...@linux.vnet.ibm.com

This patch will create 4 functions, count_opts_list, qemu_opts_append,


s/will create/creates/ - commit messages make the most sense when
written in present tense


qemu_opts_free and qemu_opts_print_help, they will be used in following
commits.



Again, this portion...


v12-v13:
1) simply assert that neither argument has merge_lists set.
2) drop superfluous paranthesesis around p == first.

v11-v12:
1) renmae functions.
2) fix loop styles and code styles.
3) qemu_opts_apend will not return NULL now.
4) merge_lists value is from arguments in qemu_opts_append.

v6-v7:
1) Fix typo.

v5-v6:
1) allocate enough space in append_opts_list function.


...belongs after '---', and



Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Dongxu Wang wdon...@linux.vnet.ibm.com


your s-o-b is unusual.



+
+static size_t count_opts_list(QemuOptsList *list)
+{
+size_t i = 0;
+
+for (i = 0; list  list-desc[i].name; i++) {


No need to initialize i to 0 in two places.


Okay.

+;
+}
+
+return i;
+}
+
+/* Create a new QemuOptsList and make its desc to the merge of first
+ * and second. It will allocate space for one new QemuOptsList plus
+ * enough space for QemuOptDesc in first and second QemuOptsList.
+ * First argument's QemuOptDesc members take precedence over second's.
+ * The result's name and implied_opt_name are not copied from them.
+ * Both merge_lists should not be set. Both list can be NULL.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *first,
+   QemuOptsList *second)
+{
+size_t num_first_opts, num_second_opts;
+QemuOptsList *dest = NULL;
+int i = 0;
+int index = 0;
+QemuOptsList *p = first;
+
+num_first_opts = count_opts_list(first);
+num_second_opts = count_opts_list(second);
+
+dest = g_malloc0(sizeof(QemuOptsList)
++ (num_first_opts + num_second_opts + 1) * sizeof(QemuOptDesc));
+
+dest-name = append_opts_list;
+dest-implied_opt_name = NULL;
+assert((!first || !first-merge_lists)
+ (!second || !second-merge_lists));
+QTAILQ_INIT(dest-head);
+
+for (i = 0; p  p-desc[i].name; i++) {


Again, a double-initialization of i [1]

Okay.



+if (!find_desc_by_name(dest-desc, p-desc[i].name)) {
+dest-desc[index].name = g_strdup(p-desc[i].name);
+dest-desc[index].help = g_strdup(p-desc[i].help);
+dest-desc[index].type = p-desc[i].type;
+dest-desc[index].def_value_str =
+g_strdup(p-desc[i].def_value_str);


Do we really have to strdup these elements, or are we guaranteed that
the scope of the original first/second list is always larger than the
scope of the merged list, and can thus share the existing pointer rather
than creating copies? [2]

I think yes, will use pointer directly in next version.



+index++;
+}
+if (p == first  p  !p-desc[i].name) {
+p = second;
+i = 0;
+}
+}
+dest-desc[index].name = NULL;
+return dest;
+}
+
+/* free a QemuOptsList, can accept NULL as arguments */
+void qemu_opts_free(QemuOptsList *list)
+{
+int i = 0;
+
+for (i = 0; list  list-desc[i].name; i++) {


[1] and again for double initialization of i


+g_free((char *)list-desc[i].name);
+g_free((char *)list-desc[i].help);
+g_free((char *)list-desc[i].def_value_str);


[2] The fact that you have to cast away const is a sign that maybe you
shouldn't be storing strdup'd data in these pointers in the first place.


+}
+
+g_free(list);
+}
+
+void qemu_opts_print_help(QemuOptsList *list)
+{
+int i = 0;
+printf(Supported options:\n);
+for (i = 0; list  list-desc[i].name; i++) {


[1] and another


+printf(%-16s %s\n, list-desc[i].name,
+list-desc[i].help ?
+list-desc[i].help : No description available);
+}
+}








[no subject]

2011-01-25 Thread Dongxu Wang