Re: [Devel] [PATCH] ext4: Discard preallocated block before swap_extents

2016-09-23 Thread Maxim Patlasov

Dima,


The patch looks fine and it works in my tests, but it slightly changes 
user-visible behavior: before patch, if ioctl(MOVE) failed, the user 
always saw moved_len=0. Now, with the patch applied, it can be !=0. 
(because ext4_ioctl() copies "me" back to user even if err != 0)



I understand that it matter of taste, but the code is more readable 
(imho) if all functions keep output args intact on failure. Hence, it 
would be nice to accumulate "cur_len" in some local var and then, in the 
end of ext4_move_extents, assign *moved_len only if ret == 0.



The above is pretty minor, so:

Reviewed-by: Maxim Patlasov 

Thanks,
Maxim


On 09/20/2016 10:41 AM, Dmitry Monakhov wrote:

Inode preallocation consists of two parts (used and unused) fully controlled
by inode, so it must be discarded before swap extents.
Currently we may skip drop_preallocation if file is sparse.

This patch does:
- Moves ext4_discard_preallocations to ext4_swap_extents.
   This makes more readable and reliable for future changes.
- Cleanup main move_extent loop

xfstests:ext4/024 (pended: 
https://github.com/dmonakhov/xfstests/commit/7a4763963f73ea5d5bba45eefa484494aa3df7cf)
Signed-off-by: Dmitry Monakhov 
---
  fs/ext4/extents.c |  2 ++
  fs/ext4/move_extent.c | 17 +
  2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index d7ccb7f..757ffb8 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -5799,9 +5799,11 @@ ext4_swap_extents(handle_t *handle, struct inode *inode1,
BUG_ON(!inode_is_locked(inode1));
BUG_ON(!inode_is_locked(inode2));
  
+	ext4_discard_preallocations(inode1);

*erp = ext4_es_remove_extent(inode1, lblk1, count);
if (unlikely(*erp))
return 0;
+   ext4_discard_preallocations(inode2);
*erp = ext4_es_remove_extent(inode2, lblk2, count);
if (unlikely(*erp))
return 0;
diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index 6fc14de..24a9586 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -632,7 +632,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, 
__u64 orig_blk,
  
  		ret = get_ext_path(orig_inode, o_start, );

if (ret)
-   goto out;
+   break;
ex = path[path->p_depth].p_ext;
next_blk = ext4_ext_next_allocated_block(path);
cur_blk = le32_to_cpu(ex->ee_block);
@@ -642,7 +642,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, 
__u64 orig_blk,
if (next_blk == EXT_MAX_BLOCKS) {
o_start = o_end;
ret = -ENODATA;
-   goto out;
+   break;
}
d_start += next_blk - o_start;
o_start = next_blk;
@@ -654,7 +654,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, 
__u64 orig_blk,
o_start = cur_blk;
/* Extent inside requested range ?*/
if (cur_blk >= o_end)
-   goto out;
+   break;
} else { /* in_range(o_start, o_blk, o_len) */
cur_len += cur_blk - o_start;
}
@@ -687,17 +687,10 @@ ext4_move_extents(struct file *o_filp, struct file 
*d_filp, __u64 orig_blk,
break;
o_start += cur_len;
d_start += cur_len;
+   *moved_len += cur_len;
}
-   *moved_len = o_start - orig_blk;
-   if (*moved_len > len)
-   *moved_len = len;
-
  out:
-   if (*moved_len) {
-   ext4_discard_preallocations(orig_inode);
-   ext4_discard_preallocations(donor_inode);
-   }
-
+   WARN_ON(*moved_len > len);
ext4_ext_drop_refs(path);
kfree(path);
ext4_double_up_write_data_sem(orig_inode, donor_inode);


___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RHEL7 COMMIT] ms/dm: remove dummy definition of 'struct dm_table'

2016-09-23 Thread Konstantin Khorenko
The commit is pushed to "branch-rh7-3.10.0-327.28.2.vz7.17.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.28.2.vz7.17.9
-->
commit 718f12861b3e5d7494b17e6a753cdef8b1f0a5f4
Author: Mike Snitzer 
Date:   Fri Sep 23 18:15:11 2016 +0400

ms/dm: remove dummy definition of 'struct dm_table'

Change the map pointer in 'struct mapped_device' from 'struct dm_table
__rcu *' to 'void __rcu *' to avoid the need for the dummy definition.

Signed-off-by: Mike Snitzer 

https://jira.sw.ru/browse/PSBM-50727

(cherry picked from commit 1d3aa6f683b1c1a813a63339d7309cff58ba4531)
Signed-off-by: Andrey Ryabinin 
---
 drivers/md/dm.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index d9a24c9..a7993cf 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -129,14 +129,6 @@ EXPORT_SYMBOL_GPL(dm_get_rq_mapinfo);
 #define DMF_SUSPENDED_INTERNALLY 8
 
 /*
- * A dummy definition to make RCU happy.
- * struct dm_table should never be dereferenced in this file.
- */
-struct dm_table {
-   int undefined__;
-};
-
-/*
  * Work processed by per-device workqueue.
  */
 struct mapped_device {
@@ -146,11 +138,11 @@ struct mapped_device {
atomic_t open_count;
 
/*
-* The current mapping.
+* The current mapping (struct dm_table *).
 * Use dm_get_live_table{_fast} or take suspend_lock for
 * dereference.
 */
-   struct dm_table __rcu *map;
+   void __rcu *map;
 
struct list_head table_devices;
struct mutex table_devices_lock;
@@ -2694,7 +2686,7 @@ static struct dm_table *__bind(struct mapped_device *md, 
struct dm_table *t,
merge_is_optional = dm_table_merge_is_optional(t);
 
old_map = rcu_dereference_protected(md->map, 
lockdep_is_held(>suspend_lock));
-   rcu_assign_pointer(md->map, t);
+   rcu_assign_pointer(md->map, (void *)t);
md->immutable_target_type = dm_table_get_immutable_target_type(t);
 
dm_table_set_restrictions(t, q, limits);
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [PATCH rh7 2/2] ms/dm: remove dummy definition of 'struct dm_table'

2016-09-23 Thread Andrey Ryabinin


On 09/23/2016 05:13 PM, Konstantin Khorenko wrote:
> Why mainstream still keeps it?
> 

By mistake, I guess.

> -- 
> Best regards,
> 
> Konstantin Khorenko,
> Virtuozzo Linux Kernel Team
> 
> On 09/22/2016 07:44 PM, Andrey Ryabinin wrote:
>> There is no need for it.
>>
>> https://jira.sw.ru/browse/PSBM-50727
>>
>> Signed-off-by: Andrey Ryabinin 
>> ---
>>  drivers/md/dm-ioctl.c | 8 
>>  1 file changed, 8 deletions(-)
>>
>> diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
>> index 720ceeb..0fe4233 100644
>> --- a/drivers/md/dm-ioctl.c
>> +++ b/drivers/md/dm-ioctl.c
>> @@ -36,14 +36,6 @@ struct hash_cell {
>>  struct dm_table *new_map;
>>  };
>>
>> -/*
>> - * A dummy definition to make RCU happy.
>> - * struct dm_table should never be dereferenced in this file.
>> - */
>> -struct dm_table {
>> -int undefined__;
>> -};
>> -
>>  struct vers_iter {
>>  size_t param_size;
>>  struct dm_target_versions *vers, *old_vers;
>>
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [PATCH RH7] sysctl: panic only on softlockup_panic-th consequent softlockup

2016-09-23 Thread Konstantin Khorenko

Pasha,

1) please write a good description. Why it's needed? How to use?
2) i thought we came up to the variant when sysctl defines not the number of 
softlockups in a row,
   but the delay in seconds?
3) please put the reviewer

Thank you.

--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

On 09/21/2016 05:27 PM, Pavel Tikhomirov wrote:

https://jira.sw.ru/browse/PSBM-52199

Signed-off-by: Pavel Tikhomirov 
---
 kernel/sysctl.c   |  3 ++-
 kernel/watchdog.c | 36 +++-
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index c8f7bc3..40dfc98 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -123,6 +123,7 @@ EXPORT_SYMBOL(ve_allow_module_load);
 #ifdef CONFIG_LOCKUP_DETECTOR
 static int sixty = 60;
 static int neg_one = -1;
+static int int_max = INT_MAX;
 #endif

 static int zero;
@@ -910,7 +911,7 @@ static struct ctl_table kern_table[] = {
.mode   = 0644,
.proc_handler   = proc_dointvec_minmax,
.extra1 = ,
-   .extra2 = ,
+   .extra2 = _max,
},
 #ifdef CONFIG_SMP
{
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index ba61141..171255b 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -304,6 +304,40 @@ static void watchdog_interrupt_count(void)
 static int watchdog_nmi_enable(unsigned int cpu);
 static void watchdog_nmi_disable(unsigned int cpu);

+/*
+ * Delay panic until softlockup_panic softlockups in raw.
+ * Consider softlockups are in raw if they fit in interval
+ * of twice as softlockup_panic * softlockup_thresh.
+ * (Soft lockups most likely will come one just after another
+ * with period of softlockup_thresh, but to cover the accumulating
+ * error give them twice as much the time as teoreticaly needed.)
+ */
+
+static int need_panic_on_softlockup(void)
+{
+   static raw_spinlock_t lock = __RAW_SPIN_LOCK_UNLOCKED(lock);
+   static unsigned long intend;
+   static int count;
+   static int thresh;
+   unsigned long now = get_timestamp();
+   int slp = softlockup_panic;
+
+   if (!slp)
+   return 0;
+
+   raw_spin_lock();
+   if (!intend || time_after(now, intend)) {
+   intend = now + 2 * slp * get_softlockup_thresh();
+   thresh = slp;
+   count = 0;
+   }
+   if (++count >= thresh)
+   return 1;
+   raw_spin_unlock();
+
+   return 0;
+}
+
 /* watchdog kicker functions */
 static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
 {
@@ -390,7 +424,7 @@ static enum hrtimer_restart watchdog_timer_fn(struct 
hrtimer *hrtimer)
}

add_taint(TAINT_SOFTLOCKUP, LOCKDEP_STILL_OK);
-   if (softlockup_panic)
+   if (need_panic_on_softlockup())
panic("softlockup: hung tasks");
__this_cpu_write(soft_watchdog_warn, true);
} else


___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RH7 v2] pfcache: hide trusted.pfcache from listxattr

2016-09-23 Thread Pavel Tikhomirov
In SyS_listxattr -> listxattr -> ext4_listxattr ->
ext4_xattr_list_entries we choose list handler for
each ext4_xattr_entry based on e_name_index, and as
for trusted.pfcache index is EXT4_XATTR_INDEX_TRUSTED,
we chouse ext4_xattr_trusted_list which always prints
xattr to the list.

When there is no PFCACHE_CSUM on superblock we do
not allow get/set trusted.pfcache, so hide it from
list too. To do so - change it's e_name_index to new
EXT4_XATTR_INDEX_TRUSTED_CSUM and thus use
ext4_xattr_trusted_csum_list. Check PFCACHE_CSUM
in it, and if no - do not print xattr to list.

Also do not allow list without global CAP_SYS_ADMIN,
as we do not allow set/get without it.

Test:

TEST_FILE=/vz/root/101/testfile
rm -f $TEST_FILE
touch $TEST_FILE
TEST_SHA1=`sha1sum $TEST_FILE | awk '{print $1}'`
setfattr -n trusted.pfcache -v $TEST_SHA1 $TEST_FILE
setfattr -n trusted.test -v test $TEST_FILE
getfattr -d -m trusted $TEST_FILE

  trusted.pfcache="da39a3ee5e6b4b0d3255bfef95601890afd80709"
  trusted.test="test"

mount -oremount,nopfcache_csum /vz/root/101
getfattr -d -m trusted $TEST_FILE

  trusted.test="test"

v2: hide only if nopfcache_csum

https://jira.sw.ru/browse/PSBM-52180
Signed-off-by: Pavel Tikhomirov 
---
 fs/ext4/pfcache.c | 45 ++---
 fs/ext4/xattr.c   |  1 +
 fs/ext4/xattr.h   |  1 +
 3 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/fs/ext4/pfcache.c b/fs/ext4/pfcache.c
index ff2300b..52bd886 100644
--- a/fs/ext4/pfcache.c
+++ b/fs/ext4/pfcache.c
@@ -441,8 +441,8 @@ int ext4_load_data_csum(struct inode *inode)
 {
int ret;
 
-   ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
-   EXT4_DATA_CSUM_NAME, EXT4_I(inode)->i_data_csum,
+   ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+   "", EXT4_I(inode)->i_data_csum,
EXT4_DATA_CSUM_SIZE);
if (ret < 0)
return ret;
@@ -482,8 +482,8 @@ static int ext4_save_data_csum(struct inode *inode, u8 
*csum)
if (ret)
return ret;
 
-   return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
-   EXT4_DATA_CSUM_NAME, EXT4_I(inode)->i_data_csum,
+   return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+   "", EXT4_I(inode)->i_data_csum,
EXT4_DATA_CSUM_SIZE, 0);
 }
 
@@ -492,8 +492,8 @@ void ext4_load_dir_csum(struct inode *inode)
char value[EXT4_DIR_CSUM_VALUE_LEN];
int ret;
 
-   ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
-EXT4_DATA_CSUM_NAME, value, sizeof(value));
+   ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+"", value, sizeof(value));
if (ret == EXT4_DIR_CSUM_VALUE_LEN &&
!strncmp(value, EXT4_DIR_CSUM_VALUE, sizeof(value)))
ext4_set_inode_state(inode, EXT4_STATE_PFCACHE_CSUM);
@@ -502,8 +502,8 @@ void ext4_load_dir_csum(struct inode *inode)
 void ext4_save_dir_csum(struct inode *inode)
 {
ext4_set_inode_state(inode, EXT4_STATE_PFCACHE_CSUM);
-   ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
-   EXT4_DATA_CSUM_NAME,
+   ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+   "",
EXT4_DIR_CSUM_VALUE,
EXT4_DIR_CSUM_VALUE_LEN, 0);
 }
@@ -516,8 +516,8 @@ void ext4_truncate_data_csum(struct inode *inode, loff_t 
pos)
 
if (EXT4_I(inode)->i_data_csum_end < 0) {
WARN_ON(journal_current_handle());
-   ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
-   EXT4_DATA_CSUM_NAME, NULL, 0, 0);
+   ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+   "", NULL, 0, 0);
ext4_close_pfcache(inode);
}
spin_lock(>i_lock);
@@ -658,8 +658,8 @@ static int ext4_xattr_trusted_csum_get(struct dentry 
*dentry, const char *name,
return -EPERM;
 
if (S_ISDIR(inode->i_mode))
-   return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
- EXT4_DATA_CSUM_NAME, buffer, size);
+   return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+ "", buffer, size);
 
if (!S_ISREG(inode->i_mode))
return -ENODATA;
@@ -717,8 +717,8 @@ static int ext4_xattr_trusted_csum_set(struct dentry 
*dentry, const char *name,
else
return -EINVAL;
 
-   return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
- EXT4_DATA_CSUM_NAME, value, size, flags);
+   return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+ "", value, size, flags);
}
 
if 

Re: [Devel] [PATCH rh7 2/2] ms/dm: remove dummy definition of 'struct dm_table'

2016-09-23 Thread Konstantin Khorenko

Why mainstream still keeps it?

--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

On 09/22/2016 07:44 PM, Andrey Ryabinin wrote:

There is no need for it.

https://jira.sw.ru/browse/PSBM-50727

Signed-off-by: Andrey Ryabinin 
---
 drivers/md/dm-ioctl.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 720ceeb..0fe4233 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -36,14 +36,6 @@ struct hash_cell {
struct dm_table *new_map;
 };

-/*
- * A dummy definition to make RCU happy.
- * struct dm_table should never be dereferenced in this file.
- */
-struct dm_table {
-   int undefined__;
-};
-
 struct vers_iter {
 size_t param_size;
 struct dm_target_versions *vers, *old_vers;


___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RHEL7 COMMIT] ms/dm: remove dummy definition of 'struct dm_table' from dm-ioctl.c

2016-09-23 Thread Konstantin Khorenko
The commit is pushed to "branch-rh7-3.10.0-327.28.2.vz7.17.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.28.2.vz7.17.9
-->
commit 1347427ba3370f15348561cc4ca46c402b85c984
Author: Andrey Ryabinin 
Date:   Fri Sep 23 18:15:12 2016 +0400

ms/dm: remove dummy definition of 'struct dm_table' from dm-ioctl.c

There is no need for it.

https://jira.sw.ru/browse/PSBM-50727

Signed-off-by: Andrey Ryabinin 
---
 drivers/md/dm-ioctl.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 720ceeb..0fe4233 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -36,14 +36,6 @@ struct hash_cell {
struct dm_table *new_map;
 };
 
-/*
- * A dummy definition to make RCU happy.
- * struct dm_table should never be dereferenced in this file.
- */
-struct dm_table {
-   int undefined__;
-};
-
 struct vers_iter {
 size_t param_size;
 struct dm_target_versions *vers, *old_vers;
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RHEL7 COMMIT] pfcache: hide trusted.pfcache from listxattr

2016-09-23 Thread Konstantin Khorenko
The commit is pushed to "branch-rh7-3.10.0-327.28.2.vz7.17.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.28.2.vz7.17.9
-->
commit 00ebb1860eff85759f1b43d795c328311c684b0e
Author: Pavel Tikhomirov 
Date:   Fri Sep 23 18:03:26 2016 +0400

pfcache: hide trusted.pfcache from listxattr

In SyS_listxattr -> listxattr -> ext4_listxattr ->
ext4_xattr_list_entries we choose list handler for
each ext4_xattr_entry based on e_name_index, and as
for trusted.pfcache index is EXT4_XATTR_INDEX_TRUSTED,
we chouse ext4_xattr_trusted_list which always prints
xattr to the list.

When there is no PFCACHE_CSUM on superblock we do
not allow get/set trusted.pfcache, so hide it from
list too. To do so - change it's e_name_index to new
EXT4_XATTR_INDEX_TRUSTED_CSUM and thus use
ext4_xattr_trusted_csum_list. Check PFCACHE_CSUM
in it, and if no - do not print xattr to list.

Also do not allow list without global CAP_SYS_ADMIN,
as we do not allow set/get without it.

Test:

TEST_FILE=/vz/root/101/testfile
rm -f $TEST_FILE
touch $TEST_FILE
TEST_SHA1=`sha1sum $TEST_FILE | awk '{print $1}'`
setfattr -n trusted.pfcache -v $TEST_SHA1 $TEST_FILE
setfattr -n trusted.test -v test $TEST_FILE
getfattr -d -m trusted $TEST_FILE

  trusted.pfcache="da39a3ee5e6b4b0d3255bfef95601890afd80709"
  trusted.test="test"

mount -oremount,nopfcache_csum /vz/root/101
getfattr -d -m trusted $TEST_FILE

  trusted.test="test"

v2: hide only if nopfcache_csum

https://jira.sw.ru/browse/PSBM-52180
Signed-off-by: Pavel Tikhomirov 
---
 fs/ext4/pfcache.c | 45 ++---
 fs/ext4/xattr.c   |  1 +
 fs/ext4/xattr.h   |  1 +
 3 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/fs/ext4/pfcache.c b/fs/ext4/pfcache.c
index ff2300b..52bd886 100644
--- a/fs/ext4/pfcache.c
+++ b/fs/ext4/pfcache.c
@@ -441,8 +441,8 @@ int ext4_load_data_csum(struct inode *inode)
 {
int ret;
 
-   ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
-   EXT4_DATA_CSUM_NAME, EXT4_I(inode)->i_data_csum,
+   ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+   "", EXT4_I(inode)->i_data_csum,
EXT4_DATA_CSUM_SIZE);
if (ret < 0)
return ret;
@@ -482,8 +482,8 @@ static int ext4_save_data_csum(struct inode *inode, u8 
*csum)
if (ret)
return ret;
 
-   return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
-   EXT4_DATA_CSUM_NAME, EXT4_I(inode)->i_data_csum,
+   return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+   "", EXT4_I(inode)->i_data_csum,
EXT4_DATA_CSUM_SIZE, 0);
 }
 
@@ -492,8 +492,8 @@ void ext4_load_dir_csum(struct inode *inode)
char value[EXT4_DIR_CSUM_VALUE_LEN];
int ret;
 
-   ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
-EXT4_DATA_CSUM_NAME, value, sizeof(value));
+   ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+"", value, sizeof(value));
if (ret == EXT4_DIR_CSUM_VALUE_LEN &&
!strncmp(value, EXT4_DIR_CSUM_VALUE, sizeof(value)))
ext4_set_inode_state(inode, EXT4_STATE_PFCACHE_CSUM);
@@ -502,8 +502,8 @@ void ext4_load_dir_csum(struct inode *inode)
 void ext4_save_dir_csum(struct inode *inode)
 {
ext4_set_inode_state(inode, EXT4_STATE_PFCACHE_CSUM);
-   ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
-   EXT4_DATA_CSUM_NAME,
+   ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+   "",
EXT4_DIR_CSUM_VALUE,
EXT4_DIR_CSUM_VALUE_LEN, 0);
 }
@@ -516,8 +516,8 @@ void ext4_truncate_data_csum(struct inode *inode, loff_t 
pos)
 
if (EXT4_I(inode)->i_data_csum_end < 0) {
WARN_ON(journal_current_handle());
-   ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
-   EXT4_DATA_CSUM_NAME, NULL, 0, 0);
+   ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+   "", NULL, 0, 0);
ext4_close_pfcache(inode);
}
spin_lock(>i_lock);
@@ -658,8 +658,8 @@ static int ext4_xattr_trusted_csum_get(struct dentry 
*dentry, const char *name,
return -EPERM;
 
if (S_ISDIR(inode->i_mode))
-   return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
- EXT4_DATA_CSUM_NAME, buffer, size);
+   return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
+ "", buffer, size);
 
if (!S_ISREG(inode->i_mode))
 

Re: [Devel] [PATCH RHEL7 COMMIT] Revert "ms/ovl: update atime on upperovl: update atime on upper"

2016-09-23 Thread Konstantin Khorenko

reapplied in rh7-3.10.0-327.28.2.vz7.17.10

--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

On 09/21/2016 04:54 PM, Konstantin Khorenko wrote:

The commit is pushed to "branch-rh7-3.10.0-327.28.2.vz7.17.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.28.2.vz7.17.8
-->
commit d3dc167710ea15dbbd77bb88f3d10d51e4600789
Author: Konstantin Khorenko 
Date:   Wed Sep 21 17:53:09 2016 +0400

Revert "ms/ovl: update atime on upperovl: update atime on upper"

Temporary revert due to panic:
https://jira.sw.ru/browse/PSBM-52373

This reverts commit 72814686c2596add559bba25d551af93193b0287.
---
 fs/overlayfs/dir.c   |  1 -
 fs/overlayfs/inode.c | 29 +++--
 fs/overlayfs/overlayfs.h |  4 
 fs/overlayfs/super.c |  8 ++--
 4 files changed, 5 insertions(+), 37 deletions(-)

diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 881987c..5402b9b 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -966,7 +966,6 @@ const struct inode_operations_wrapper 
ovl_dir_inode_operations = {
.getxattr   = ovl_getxattr,
.listxattr  = ovl_listxattr,
.removexattr= ovl_removexattr,
-   .update_time= ovl_update_time,
},
.rename2= ovl_rename2,
 };
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index 77f2da4..5fe7acf 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -196,6 +196,8 @@ static int ovl_readlink(struct dentry *dentry, char __user 
*buf, int bufsiz)
if (!realinode->i_op->readlink)
return -EINVAL;

+   touch_atime();
+
return realinode->i_op->readlink(realpath.dentry, buf, bufsiz);
 }

@@ -381,29 +383,6 @@ struct inode *ovl_d_select_inode(struct dentry *dentry)
return d_backing_inode(realpath.dentry);
 }

-int ovl_update_time(struct inode *inode, struct timespec *ts, int flags)
-{
-   struct dentry *alias;
-   struct path upperpath;
-
-   if (!(flags & S_ATIME))
-   return 0;
-
-   alias = d_find_any_alias(inode);
-   if (!alias)
-   return 0;
-
-   ovl_path_upper(alias, );
-   if (upperpath.dentry) {
-   touch_atime();
-   inode->i_atime = d_inode(upperpath.dentry)->i_atime;
-   }
-
-   dput(alias);
-
-   return 0;
-}
-
 static const struct inode_operations_wrapper ovl_file_inode_operations = {
.ops = {
.setattr= ovl_setattr,
@@ -413,7 +392,6 @@ static const struct inode_operations_wrapper 
ovl_file_inode_operations = {
.getxattr   = ovl_getxattr,
.listxattr  = ovl_listxattr,
.removexattr= ovl_removexattr,
-   .update_time= ovl_update_time,
},
.dentry_open= ovl_dentry_open,
 };
@@ -428,7 +406,6 @@ static const struct inode_operations 
ovl_symlink_inode_operations = {
.getxattr   = ovl_getxattr,
.listxattr  = ovl_listxattr,
.removexattr= ovl_removexattr,
-   .update_time= ovl_update_time,
 };

 struct inode *ovl_new_inode(struct super_block *sb, umode_t mode,
@@ -444,7 +421,7 @@ struct inode *ovl_new_inode(struct super_block *sb, umode_t 
mode,

inode->i_ino = get_next_ino();
inode->i_mode = mode;
-   inode->i_flags |= S_NOCMTIME;
+   inode->i_flags |= S_NOATIME | S_NOCMTIME;

switch (mode) {
case S_IFDIR:
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 61ba0d5..8da9684 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -174,7 +174,6 @@ ssize_t ovl_getxattr(struct dentry *dentry, const char 
*name,
 ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
 int ovl_removexattr(struct dentry *dentry, const char *name);
 struct inode *ovl_d_select_inode(struct dentry *dentry);
-int ovl_update_time(struct inode *inode, struct timespec *ts, int flags);

 struct inode *ovl_new_inode(struct super_block *sb, umode_t mode,
struct ovl_entry *oe);
@@ -182,9 +181,6 @@ static inline void ovl_copyattr(struct inode *from, struct 
inode *to)
 {
to->i_uid = from->i_uid;
to->i_gid = from->i_gid;
-   to->i_atime = from->i_atime;
-   to->i_mtime = from->i_mtime;
-   to->i_ctime = from->i_ctime;
 }

 /* dir.c */
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index b46463a..2935967 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -533,7 +533,7 @@ out:

 struct file *ovl_path_open(struct path *path, int flags)
 {
-   return dentry_open(path, flags | O_NOATIME, current_cred());
+   return dentry_open(path, flags, current_cred());
 }

 static void ovl_put_super(struct super_block *sb)
@@ -1013,10 +1013,6 @@ static int ovl_fill_super(struct super_block *sb, void 
*data, int silent)
pr_err("overlayfs: failed to clone upperpath\n");
 

Re: [Devel] [PATCH RHEL7 COMMIT] Revert "fs: use original vfsmount for touch_atime"

2016-09-23 Thread Konstantin Khorenko

reapplied in rh7-3.10.0-327.28.2.vz7.17.10

--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

On 09/21/2016 04:52 PM, Konstantin Khorenko wrote:

The commit is pushed to "branch-rh7-3.10.0-327.28.2.vz7.17.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.28.2.vz7.17.8
-->
commit 5ca9c58d75751a11522dd129ddeb5a894a227896
Author: Konstantin Khorenko 
Date:   Wed Sep 21 17:51:42 2016 +0400

Revert "fs: use original vfsmount for touch_atime"

Temporary revert due to panic:
https://jira.sw.ru/browse/PSBM-52373

This reverts commit a427c4dfb7514de4701ad5f51e4f9442a495131c.
---
 fs/open.c  | 3 ---
 include/linux/fs.h | 4 +---
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index 8c066b1..bc60c05 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -894,9 +894,6 @@ int vfs_open(const struct path *path, struct file *filp,
struct inode *inode = path->dentry->d_inode;
iop_dentry_open_t dentry_open = get_dentry_open_iop(inode);

-   if (!filp->f_original_path.mnt)
-   filp->f_original_path = *path;
-
if (dentry_open)
return dentry_open(path->dentry, filp, cred);
else {
diff --git a/include/linux/fs.h b/include/linux/fs.h
index ed9519f..7203dba 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -959,7 +959,6 @@ struct file {
struct rcu_head fu_rcuhead;
} f_u;
struct path f_path;
-   struct path f_original_path;
 #define f_dentry   f_path.dentry
struct inode*f_inode;   /* cached value */
const struct file_operations*f_op;
@@ -2094,8 +2093,7 @@ extern void touch_atime(struct path *);
 static inline void file_accessed(struct file *file)
 {
if (!(file->f_flags & O_NOATIME))
-   touch_atime(file->f_original_path.mnt ?
-   >f_original_path : >f_path);
+   touch_atime(>f_path);
 }

 int sync_inode(struct inode *inode, struct writeback_control *wbc);
.


___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RHEL7 COMMIT] fs: hold reference on original path

2016-09-23 Thread Konstantin Khorenko
The commit is pushed to "branch-rh7-3.10.0-327.28.2.vz7.17.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.28.2.vz7.17.9
-->
commit 0c898c51709daf78d1704b90bec1395cadeb3a51
Author: Maxim Patlasov 
Date:   Fri Sep 23 17:32:01 2016 +0400

fs: hold reference on original path

struct file holds references on its f_path.mnt and f_path.dentry by calling
path_get(>f_path) from do_dentry_open(). Let's use the same technique
for f->f_original_path. Otherwise, f_original_path.dentry can be deleted 
while
file still references it leading to NULL-ptr-deref on 
f->f_original_path.dentry->d_inode.

https://jira.sw.ru/browse/PSBM-52373

Signed-off-by: Maxim Patlasov 
Reviewed-by: Kirill Tkhai 
---
 fs/file_table.c |  6 ++
 fs/open.c   | 18 +++---
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/fs/file_table.c b/fs/file_table.c
index 957c476..b8982d8 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -242,6 +242,8 @@ static void __fput(struct file *file)
struct dentry *dentry = file->f_path.dentry;
struct vfsmount *mnt = file->f_path.mnt;
struct inode *inode = dentry->d_inode;
+   struct dentry *original_dentry = file->f_original_path.dentry;
+   struct vfsmount *original_mnt = file->f_original_path.mnt;
 
might_sleep();
 
@@ -273,10 +275,14 @@ static void __fput(struct file *file)
drop_file_write_access(file);
file->f_path.dentry = NULL;
file->f_path.mnt = NULL;
+   file->f_original_path.dentry = NULL;
+   file->f_original_path.mnt = NULL;
file->f_inode = NULL;
file_free(file);
dput(dentry);
mntput(mnt);
+   dput(original_dentry);
+   mntput(original_mnt);
 }
 
 static DEFINE_SPINLOCK(delayed_fput_lock);
diff --git a/fs/open.c b/fs/open.c
index 8c066b1..25dbc85 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -893,16 +893,28 @@ int vfs_open(const struct path *path, struct file *filp,
 {
struct inode *inode = path->dentry->d_inode;
iop_dentry_open_t dentry_open = get_dentry_open_iop(inode);
+   int do_cleanup = 0;
+   int ret;
 
-   if (!filp->f_original_path.mnt)
+   if (!filp->f_original_path.mnt) {
filp->f_original_path = *path;
+   path_get(>f_original_path);
+   do_cleanup = 1;
+   }
 
if (dentry_open)
-   return dentry_open(path->dentry, filp, cred);
+   ret = dentry_open(path->dentry, filp, cred);
else {
filp->f_path = *path;
-   return do_dentry_open(filp, NULL, cred);
+   ret = do_dentry_open(filp, NULL, cred);
}
+
+   if (ret && do_cleanup) {
+   path_put(>f_original_path);
+   filp->f_original_path.mnt = NULL;
+   filp->f_original_path.dentry = NULL;
+   }
+   return ret;
 }
 EXPORT_SYMBOL(vfs_open);
 
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [PATCH RH7] pfcache: hide trusted.pfcache from listxattr

2016-09-23 Thread Dmitry Monakhov
Pavel Tikhomirov  writes:

> In SyS_listxattr -> listxattr -> ext4_listxattr ->
> ext4_xattr_list_entries we choose list handler for
> each ext4_xattr_entry based on e_name_index, and as
> for trusted.pfcache index is EXT4_XATTR_INDEX_TRUSTED,
> we chouse ext4_xattr_trusted_list which prints xattr
> to the list.
>
> To hide our trusted.pfcache from list change e_name_index
> to new EXT4_XATTR_INDEX_TRUSTED_CSUM and thus use
> ext4_xattr_trusted_csum_list instead which won't put
> xattr to the returned list.
Why we want to hide it?
>
> Test:
>
> TEST_FILE=/vz/root/101/testfile
> TEST_SHA1=`sha1sum $TEST_FILE | awk '{print $1}'`
> setfattr -n trusted.pfcache -v $TEST_SHA1 $TEST_FILE
> setfattr -n trusted.test -v test $TEST_FILE
> getfattr -d -m trusted $TEST_FILE
>
> before patch it was listed:
>
> trusted.pfcache="da39a3ee5e6b4b0d3255bfef95601890afd80709"
> trusted.test="test"
>
> after - not:
>
> trusted.test="test"
>
> https://jira.sw.ru/browse/PSBM-52180
> Signed-off-by: Pavel Tikhomirov 
> ---
>  fs/ext4/pfcache.c | 28 ++--
>  fs/ext4/xattr.c   |  1 +
>  fs/ext4/xattr.h   |  1 +
>  3 files changed, 16 insertions(+), 14 deletions(-)
>
> diff --git a/fs/ext4/pfcache.c b/fs/ext4/pfcache.c
> index ff2300b..5fc6d9f 100644
> --- a/fs/ext4/pfcache.c
> +++ b/fs/ext4/pfcache.c
> @@ -441,8 +441,8 @@ int ext4_load_data_csum(struct inode *inode)
>  {
>   int ret;
>  
> - ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
> - EXT4_DATA_CSUM_NAME, EXT4_I(inode)->i_data_csum,
> + ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
> + "", EXT4_I(inode)->i_data_csum,
>   EXT4_DATA_CSUM_SIZE);
>   if (ret < 0)
>   return ret;
> @@ -482,8 +482,8 @@ static int ext4_save_data_csum(struct inode *inode, u8 
> *csum)
>   if (ret)
>   return ret;
>  
> - return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
> - EXT4_DATA_CSUM_NAME, EXT4_I(inode)->i_data_csum,
> + return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
> + "", EXT4_I(inode)->i_data_csum,
>   EXT4_DATA_CSUM_SIZE, 0);
>  }
>  
> @@ -492,8 +492,8 @@ void ext4_load_dir_csum(struct inode *inode)
>   char value[EXT4_DIR_CSUM_VALUE_LEN];
>   int ret;
>  
> - ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
> -  EXT4_DATA_CSUM_NAME, value, sizeof(value));
> + ret = ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
> +  "", value, sizeof(value));
>   if (ret == EXT4_DIR_CSUM_VALUE_LEN &&
>   !strncmp(value, EXT4_DIR_CSUM_VALUE, sizeof(value)))
>   ext4_set_inode_state(inode, EXT4_STATE_PFCACHE_CSUM);
> @@ -502,8 +502,8 @@ void ext4_load_dir_csum(struct inode *inode)
>  void ext4_save_dir_csum(struct inode *inode)
>  {
>   ext4_set_inode_state(inode, EXT4_STATE_PFCACHE_CSUM);
> - ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
> - EXT4_DATA_CSUM_NAME,
> + ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
> + "",
>   EXT4_DIR_CSUM_VALUE,
>   EXT4_DIR_CSUM_VALUE_LEN, 0);
>  }
> @@ -516,8 +516,8 @@ void ext4_truncate_data_csum(struct inode *inode, loff_t 
> pos)
>  
>   if (EXT4_I(inode)->i_data_csum_end < 0) {
>   WARN_ON(journal_current_handle());
> - ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
> - EXT4_DATA_CSUM_NAME, NULL, 0, 0);
> + ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
> + "", NULL, 0, 0);
>   ext4_close_pfcache(inode);
>   }
>   spin_lock(>i_lock);
> @@ -658,8 +658,8 @@ static int ext4_xattr_trusted_csum_get(struct dentry 
> *dentry, const char *name,
>   return -EPERM;
>  
>   if (S_ISDIR(inode->i_mode))
> - return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED,
> -   EXT4_DATA_CSUM_NAME, buffer, size);
> + return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
> +   "", buffer, size);
>  
>   if (!S_ISREG(inode->i_mode))
>   return -ENODATA;
> @@ -717,8 +717,8 @@ static int ext4_xattr_trusted_csum_set(struct dentry 
> *dentry, const char *name,
>   else
>   return -EINVAL;
>  
> - return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED,
> -   EXT4_DATA_CSUM_NAME, value, size, flags);
> + return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED_CSUM,
> +   "", value, size, flags);
>   }
>  
>   if (!S_ISREG(inode->i_mode))
> diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> index 5dabf58..81b5534 100644
> --- a/fs/ext4/xattr.c
> +++