Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756060AbbDOHQN (ORCPT ); Wed, 15 Apr 2015 03:16:13 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:32565 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755791AbbDOHQI (ORCPT ); Wed, 15 Apr 2015 03:16:08 -0400 X-AuditID: cbfec7f4-b7f106d0000013ec-3b-552e0f7e2bb6 From: Beata Michalska To: linux-kernel@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, hughd@google.com, lczerner@redhat.com, hch@infradead.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, kyungmin.park@samsung.com, kmpark@infradead.org Subject: [RFC 4/4] shmem: Add support for generic FS events Date: Wed, 15 Apr 2015 09:15:47 +0200 Message-id: <1429082147-4151-5-git-send-email-b.michalska@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1429082147-4151-1-git-send-email-b.michalska@samsung.com> References: <1429082147-4151-1-git-send-email-b.michalska@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprALMWRmVeSWpSXmKPExsVy+t/xy7p1/HqhBo9/S1p8/dLBYnF6wiIm i6ef+lgsbl1exWJxtukNu8WyB5tZLGbOu8NmcXnXHDaLe2v+s1q09vxkd+DyaNlc7rFgU6nH 5hVaHps+TWL3aDpzlNnj/b6rbB59W1YxenzeJBfAEcVlk5Kak1mWWqRvl8CVcal/F0vBC6mK dYvbWRsYL4p2MXJySAiYSOw8MIcFwhaTuHBvPVsXIxeHkMBSRomN02cyQTi9TBIzmj+AVbEJ 6Eu8mrGSCcQWEVCQ2Nz7jBXEZhY4xSix648+iC0sYC2xpHEGM4jNIqAqMev6SjYQm1fATaL3 3WqgORxA2xQk5kyyAQlzCrhLNB9pYQexhYBKupY0MU9g5F3AyLCKUTS1NLmgOCk911CvODG3 uDQvXS85P3cTIyQUv+xgXHzM6hCjAAejEg/vh3ydUCHWxLLiytxDjBIczEoivMZ/dEOFeFMS K6tSi/Lji0pzUosPMTJxcEo1MGZ/mFPo/3GLW1jnzYuhsQUMl2N6ZuRrL2/tFjSwe6JocCL6 zLqLXdZHdHYdTenN1G29O3v5gYRyAeeciO//HqUd+cRq8o1dt3Zq/Y61UtVt7oXLemLbs81b Y702PltSPdFQMNlF78TNfZbJVz5eXpJ7byrn6yq20ofrrl48Ung8f03L94qmM0osxRmJhlrM RcWJAKNqRqkjAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3560 Lines: 122 Add support for the generic FS events interface covering threshold notifiactions and the ENOSPC warning. Signed-off-by: Beata Michalska --- mm/shmem.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index cf2d0ca..bb261ac 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -201,6 +201,7 @@ static int shmem_reserve_inode(struct super_block *sb) spin_lock(&sbinfo->stat_lock); if (!sbinfo->free_inodes) { spin_unlock(&sbinfo->stat_lock); + fs_event_notify(sb, FS_EVENT_WARN, FS_WARN_ENOSPC); return -ENOSPC; } sbinfo->free_inodes--; @@ -239,8 +240,10 @@ static void shmem_recalc_inode(struct inode *inode) freed = info->alloced - info->swapped - inode->i_mapping->nrpages; if (freed > 0) { struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); - if (sbinfo->max_blocks) + if (sbinfo->max_blocks) { percpu_counter_add(&sbinfo->used_blocks, -freed); + fs_event_free_space(inode->i_sb, freed); + } info->alloced -= freed; inode->i_blocks -= freed * BLOCKS_PER_PAGE; shmem_unacct_blocks(info->flags, freed); @@ -1164,6 +1167,7 @@ repeat: goto unacct; } percpu_counter_inc(&sbinfo->used_blocks); + fs_event_alloc_space(inode->i_sb, 1); } page = shmem_alloc_page(gfp, info, index); @@ -1245,8 +1249,10 @@ trunc: spin_unlock(&info->lock); decused: sbinfo = SHMEM_SB(inode->i_sb); - if (sbinfo->max_blocks) + if (sbinfo->max_blocks) { percpu_counter_add(&sbinfo->used_blocks, -1); + fs_event_free_space(inode->i_sb, 1); + } unacct: shmem_unacct_blocks(info->flags, 1); failed: @@ -1258,12 +1264,17 @@ unlock: unlock_page(page); page_cache_release(page); } - if (error == -ENOSPC && !once++) { + if (error == -ENOSPC) { + if (!once++) { info = SHMEM_I(inode); spin_lock(&info->lock); shmem_recalc_inode(inode); spin_unlock(&info->lock); goto repeat; + } else { + fs_event_notify(inode->i_sb, FS_EVENT_WARN, + FS_WARN_ENOSPC); + } } if (error == -EEXIST) /* from above or from radix_tree_insert */ goto repeat; @@ -2729,12 +2740,33 @@ static int shmem_encode_fh(struct inode *inode, __u32 *fh, int *len, return 1; } +static int shmem_trace_query(struct super_block *sb, + struct fs_trace_sdata *data) +{ + struct shmem_sb_info *sbinfo = SHMEM_SB(sb); + + if (!sb || !data) + return -EINVAL; + + data->events_cap_mask = FS_EVENT_WARN; + if (sbinfo->max_blocks) { + data->available_blks = sbinfo->max_blocks - + percpu_counter_sum(&sbinfo->used_blocks); + data->events_cap_mask |= FS_EVENT_THRESH; + } + return 0; +} + static const struct export_operations shmem_export_ops = { .get_parent = shmem_get_parent, .encode_fh = shmem_encode_fh, .fh_to_dentry = shmem_fh_to_dentry, }; +static const struct fs_trace_operations shmem_trace_ops = { + .fs_trace_query = shmem_trace_query, +}; + static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo, bool remount) { @@ -3020,6 +3052,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent) sb->s_flags |= MS_NOUSER; } sb->s_export_op = &shmem_export_ops; + sb->s_trace_ops = &shmem_trace_ops; sb->s_flags |= MS_NOSEC; #else sb->s_flags |= MS_NOUSER; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/