dog: fix a core dump by 'vdi lock force-unlock'

force-unlock expect an argument so we need to set CMD_NEED_ARG for it otherwise
a core will be generated by

$ dog vdi lock force-unlock # without argument

Signed-off-by: Liu Yuan <namei.unix@gmail.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
dog: rename 'force-unlock' as 'unlock'

We don't have a command named 'vdi lock unlock', so we can simply take this seat
and simplify the command line for users.

updated:
$ dog vdi lock unlock <vdiname>

Signed-off-by: Liu Yuan <namei.unix@gmail.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
dog/vdi: fix bug in dog vdi check

If condition is never satisfied since nr_copies
is the minimum of inode->nr_copies and sd_zones_nr.

Signed-off-by: Bingpeng Zhu <bingpeng.zbp@alibaba-inc.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
dog: fix cluster-wide snapshot inconsistency due to vdi deleted

Once vdi snapshot is deleted before executing 'dog cluster snapshot
save', error messsage just like as below is seen.

Failed to read object 807c2b2500000000 No object found
Failed to read inode header

Once a vdi is deleted, cluster snapshot save will not backup it to
farm so that cluster snapshot load cannot restore it to new cluster.
However, the vdi id is marked as in use for safety, vdi list
will try to read all vdis in use. Therefore, dog cannot read the object.

The solution is saving the deleted vdi object too. To achieve it,
a parameter, no_deleted, is added to the function parse_vdi.
The default value is true. But for cluster snapshot save, it is false.

Reported-by: Valerio Pachera <sirio81@gmail.com>
Cc: Liu Yuan <namei.unix@gmail.com>
Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
test/func: add test case for fixing cluster-wide snapshot inconsistency

Test suite 030 is updated.

Reported-by: Valerio Pachera <sirio81@gmail.com>
Cc: Liu Yuan <namei.unix@gmail.com>
Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
dog/vdi: replace strtoll with strtoull

oid is of uint64_t type, VDI object oid is started with 0x80,
which is large than the maximum of long long int. So, we should
replace strtoll with strtoull in function vdi_parser().

Signed-off-by: Bingpeng Zhu <bingpeng.zbp@alibaba-inc.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
dog/vdi: fix bad address error in dog vdi check

We can use dog vdi check to repair the vdi if some replica is lost.
When creating a erasure coded vdi and some data replica of the vdi
is lost, we run dog vdi check and will see the following error log
sometimes:
failed to write to socket: Bad address
If you don't see the error, you will find the file length of the
recoverd replica is not correct. It is because the replica buffer
length is not set correctly. The buffer overflows, so we get
Bad address error. This patch add the buffer length parameter for
write_object_to() function and set the buffer length correctly.

Signed-off-by: Bingpeng Zhu <bingpeng.zbp@alibaba-inc.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
sheep/oc: use strtoull instead of strtoul

Although long long data type is the same as long data type in 64-bit
platform, it is better to use only one of them. Since we use strtoull
in other place of the module, we should not use strtoul.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
dog/farm: clear performance tips generated by cppcheck

This patch gets rid of the below message while performing a code analysis
with cppcheck.

[dog/farm/farm.c:207] -> [dog/farm/farm.c:218]: (performance) Variable
'ret' is reassigned a value before the old one has been used.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
dog/vdi: clear performance tips generated by cppcheck

This patch gets rid of the below message while performing a code
analysis with cppcheck.

[dog/vdi.c:972] -> [dog/vdi.c:974]: (performance) Variable 'ret' is
reassigned a value before the old one has been used.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
http/kv: clear performance tips generated by cppcheck

This patch gets rid of the below messages while performing a code
analysis with cppcheck.

[sheep/http/kv.c:852] -> [sheep/http/kv.c:854]: (performance) Variable
'ret' is reassigned a value before the old one has been used.
[sheep/http/kv.c:919] -> [sheep/http/kv.c:923]: (performance) Variable
'ret' is reassigned a value before the old one has been used.
[sheep/http/kv.c:1242] -> [sheep/http/kv.c:1245]: (performance) Variable
'ret' is reassigned a value before the old one has been used.
[sheep/http/kv.c:1299] -> [sheep/http/kv.c:1303]: (performance) Variable
'ret' is reassigned a value before the old one has been used.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
sheep/md: clear performance tips generated by cppcheck

This patch gets rid of the below message while performing a code
analysis with cppcheck.

[sheep/md.c:395] -> [sheep/md.c:398]: (performance) Variable 'ret' is
reassigned a value before the old one has been used.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
sheep/migrate: clear performance tips generated by cppcheck

This patch gets rid of the below message while performing a code
analysis with cppcheck.

[sheep/migrate.c:117] -> [sheep/migrate.c:122]: (performance) Variable
'fd' is reassigned a value before the old one has been used.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
sheep/oc: clear performance tips generated by cppcheck

This patch gets rid of the below message while performing a code
analysis with cppcheck.

[sheep/object_cache.c:805] -> [sheep/object_cache.c:815]: (performance)
Variable 'ret' is reassigned a value before the old one has been used.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
sheep/ops: clear performance tips generated by cppcheck

This patch gets rid of the below messages while performing a code
analysis with cppcheck.

[sheep/ops.c:884] -> [sheep/ops.c:888]: (performance) Variable 'ret' is
reassigned a value before the old one has been used.
[sheep/ops.c:1149] -> [sheep/ops.c:1166]: (performance) Variable
'locked' is reassigned a value before the old one has been used.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
sheep: clear performance tips generated by cppcheck

This patch gets rid of the below message while performing a code
analysis with cppcheck.

[sheep/sheep.c:197] -> [sheep/sheep.c:201]: (performance) Variable 'fd'
is reassigned a value before the old one has been used.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
sheep/vdi: clear performance tips generated by cppcheck

This patch gets rid of the below message while performing a code
analysis with cppcheck.

[sheep/vdi.c:275] -> [sheep/vdi.c:278]: (performance) Variable 'ret' is
reassigned a value before the old one has been used.
[sheep/vdi.c:1239] -> [sheep/vdi.c:1249]: (performance) Variable 'ret'
is reassigned a value before the old one has been used.
[sheep/vdi.c:1376] -> [sheep/vdi.c:1382]: (performance) Variable 'ret'
is reassigned a value before the old one has been used.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
sheepfs/http: clear performance tips generated by cppcheck

This patch gets rid of the below message while performing a code
analysis with cppcheck.

[sheepfs/http.c:534] -> [sheepfs/http.c:537]: (performance) Variable
'ret' is reassigned a value before the old one has been used.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
dog/vdi: remove unused parameter in argument list of find_vdi_name

Because for_snapshot is never used in the function find_vdi_name,
removing it is safe and reasonable.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
dog/vdi: enhance find_vdi_name to allow returning SD_RES_XXX

Current return value of the function find_vdi_name is quite simple. -1
stands for failure and 0 stands for success. It is not enough if caller
A expects it returns information of a VDI and caller B expects it
returns the VDI is existed or not.

So, it is better to enhance it to return SD_RES_XXX.

As a result, the error message printed inside the function should be
moved to the callers.

Signed-off-by: Ruoyu <liangry@ucweb.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>