CC: [email protected]
CC: [email protected]
TO: Xiubo Li <[email protected]>
CC: Jeff Layton <[email protected]>

tree:   https://github.com/ceph/ceph-client.git testing
head:   64887ecca52b9d754c09837b7242b80463bda63c
commit: dcdb5c3121f827d6bd92a11f3ad0f0cc27e3d133 [6/8] ceph: flush the mdlog 
before waiting on unsafe reqs
:::::: branch date: 11 hours ago
:::::: commit date: 34 hours ago
config: s390-randconfig-m031-20210707 (attached as .config)
compiler: s390-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

New smatch warnings:
fs/ceph/caps.c:2272 unsafe_request_wait() warn: potentially one past the end of 
array 'sessions[s->s_mds]'
fs/ceph/caps.c:2272 unsafe_request_wait() warn: potentially one past the end of 
array 'sessions[s->s_mds]'

Old smatch warnings:
fs/ceph/caps.c:2286 unsafe_request_wait() warn: potentially one past the end of 
array 'sessions[s->s_mds]'
fs/ceph/caps.c:2286 unsafe_request_wait() warn: potentially one past the end of 
array 'sessions[s->s_mds]'

vim +2272 fs/ceph/caps.c

a8599bd821d084 Sage Weil   2009-10-06  2212  
da819c8150c5b6 Yan, Zheng  2015-05-27  2213  /*
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2214   * wait for any unsafe requests to 
complete.
da819c8150c5b6 Yan, Zheng  2015-05-27  2215   */
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2216  static int 
unsafe_request_wait(struct inode *inode)
da819c8150c5b6 Yan, Zheng  2015-05-27  2217  {
dcdb5c3121f827 Xiubo Li    2021-07-05  2218     struct ceph_mds_client *mdsc = 
ceph_sb_to_client(inode->i_sb)->mdsc;
da819c8150c5b6 Yan, Zheng  2015-05-27  2219     struct ceph_inode_info *ci = 
ceph_inode(inode);
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2220     struct ceph_mds_request *req1 = 
NULL, *req2 = NULL;
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2221     int ret, err = 0;
da819c8150c5b6 Yan, Zheng  2015-05-27  2222  
da819c8150c5b6 Yan, Zheng  2015-05-27  2223     spin_lock(&ci->i_unsafe_lock);
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2224     if (S_ISDIR(inode->i_mode) && 
!list_empty(&ci->i_unsafe_dirops)) {
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2225             req1 = 
list_last_entry(&ci->i_unsafe_dirops,
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2226                                     
struct ceph_mds_request,
da819c8150c5b6 Yan, Zheng  2015-05-27  2227                                     
r_unsafe_dir_item);
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2228             
ceph_mdsc_get_request(req1);
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2229     }
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2230     if 
(!list_empty(&ci->i_unsafe_iops)) {
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2231             req2 = 
list_last_entry(&ci->i_unsafe_iops,
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2232                                     
struct ceph_mds_request,
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2233                                     
r_unsafe_target_item);
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2234             
ceph_mdsc_get_request(req2);
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2235     }
da819c8150c5b6 Yan, Zheng  2015-05-27  2236     spin_unlock(&ci->i_unsafe_lock);
da819c8150c5b6 Yan, Zheng  2015-05-27  2237  
dcdb5c3121f827 Xiubo Li    2021-07-05  2238     /*
dcdb5c3121f827 Xiubo Li    2021-07-05  2239      * Trigger to flush the journal 
logs in all the relevant MDSes
dcdb5c3121f827 Xiubo Li    2021-07-05  2240      * manually, or in the worst 
case we must wait at most 5 seconds
dcdb5c3121f827 Xiubo Li    2021-07-05  2241      * to wait the journal logs to 
be flushed by the MDSes periodically.
dcdb5c3121f827 Xiubo Li    2021-07-05  2242      */
dcdb5c3121f827 Xiubo Li    2021-07-05  2243     if (req1 || req2) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2244             struct ceph_mds_session 
**sessions = NULL;
dcdb5c3121f827 Xiubo Li    2021-07-05  2245             struct ceph_mds_session 
*s;
dcdb5c3121f827 Xiubo Li    2021-07-05  2246             struct ceph_mds_request 
*req;
dcdb5c3121f827 Xiubo Li    2021-07-05  2247             unsigned int max;
dcdb5c3121f827 Xiubo Li    2021-07-05  2248             int i;
dcdb5c3121f827 Xiubo Li    2021-07-05  2249  
dcdb5c3121f827 Xiubo Li    2021-07-05  2250             /*
dcdb5c3121f827 Xiubo Li    2021-07-05  2251              * The 
mdsc->max_sessions is unlikely to be changed
dcdb5c3121f827 Xiubo Li    2021-07-05  2252              * mostly, here we will 
retry it by reallocating the
dcdb5c3121f827 Xiubo Li    2021-07-05  2253              * sessions arrary 
memory to get rid of the mdsc->mutex
dcdb5c3121f827 Xiubo Li    2021-07-05  2254              * lock.
dcdb5c3121f827 Xiubo Li    2021-07-05  2255              */
dcdb5c3121f827 Xiubo Li    2021-07-05  2256  retry:
dcdb5c3121f827 Xiubo Li    2021-07-05  2257             max = 
mdsc->max_sessions;
dcdb5c3121f827 Xiubo Li    2021-07-05  2258             sessions = 
krealloc(sessions, max * sizeof(s), __GFP_ZERO);
dcdb5c3121f827 Xiubo Li    2021-07-05  2259             if (!sessions) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2260                     err = -ENOMEM;
dcdb5c3121f827 Xiubo Li    2021-07-05  2261                     goto out;
dcdb5c3121f827 Xiubo Li    2021-07-05  2262             }
dcdb5c3121f827 Xiubo Li    2021-07-05  2263             
spin_lock(&ci->i_unsafe_lock);
dcdb5c3121f827 Xiubo Li    2021-07-05  2264             if (req1) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2265                     
list_for_each_entry(req, &ci->i_unsafe_dirops,
dcdb5c3121f827 Xiubo Li    2021-07-05  2266                                     
    r_unsafe_dir_item) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2267                             s = 
req->r_session;
dcdb5c3121f827 Xiubo Li    2021-07-05  2268                             if 
(unlikely(s->s_mds > max)) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2269                                     
spin_unlock(&ci->i_unsafe_lock);
dcdb5c3121f827 Xiubo Li    2021-07-05  2270                                     
goto retry;
dcdb5c3121f827 Xiubo Li    2021-07-05  2271                             }
dcdb5c3121f827 Xiubo Li    2021-07-05 @2272                             if 
(!sessions[s->s_mds]) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2273                                     
s = ceph_get_mds_session(s);
dcdb5c3121f827 Xiubo Li    2021-07-05  2274                                     
sessions[s->s_mds] = s;
dcdb5c3121f827 Xiubo Li    2021-07-05  2275                             }
dcdb5c3121f827 Xiubo Li    2021-07-05  2276                     }
dcdb5c3121f827 Xiubo Li    2021-07-05  2277             }
dcdb5c3121f827 Xiubo Li    2021-07-05  2278             if (req2) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2279                     
list_for_each_entry(req, &ci->i_unsafe_iops,
dcdb5c3121f827 Xiubo Li    2021-07-05  2280                                     
    r_unsafe_target_item) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2281                             s = 
req->r_session;
dcdb5c3121f827 Xiubo Li    2021-07-05  2282                             if 
(unlikely(s->s_mds > max)) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2283                                     
spin_unlock(&ci->i_unsafe_lock);
dcdb5c3121f827 Xiubo Li    2021-07-05  2284                                     
goto retry;
dcdb5c3121f827 Xiubo Li    2021-07-05  2285                             }
dcdb5c3121f827 Xiubo Li    2021-07-05  2286                             if 
(!sessions[s->s_mds]) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2287                                     
s = ceph_get_mds_session(s);
dcdb5c3121f827 Xiubo Li    2021-07-05  2288                                     
sessions[s->s_mds] = s;
dcdb5c3121f827 Xiubo Li    2021-07-05  2289                             }
dcdb5c3121f827 Xiubo Li    2021-07-05  2290                     }
dcdb5c3121f827 Xiubo Li    2021-07-05  2291             }
dcdb5c3121f827 Xiubo Li    2021-07-05  2292             
spin_unlock(&ci->i_unsafe_lock);
dcdb5c3121f827 Xiubo Li    2021-07-05  2293  
dcdb5c3121f827 Xiubo Li    2021-07-05  2294             /* the auth MDS */
dcdb5c3121f827 Xiubo Li    2021-07-05  2295             
spin_lock(&ci->i_ceph_lock);
dcdb5c3121f827 Xiubo Li    2021-07-05  2296             if (ci->i_auth_cap) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2297                   s = 
ci->i_auth_cap->session;
dcdb5c3121f827 Xiubo Li    2021-07-05  2298                   if 
(!sessions[s->s_mds])
dcdb5c3121f827 Xiubo Li    2021-07-05  2299                           
sessions[s->s_mds] = ceph_get_mds_session(s);
dcdb5c3121f827 Xiubo Li    2021-07-05  2300             }
dcdb5c3121f827 Xiubo Li    2021-07-05  2301             
spin_unlock(&ci->i_ceph_lock);
dcdb5c3121f827 Xiubo Li    2021-07-05  2302  
dcdb5c3121f827 Xiubo Li    2021-07-05  2303             /* send flush mdlog 
request to MDSes */
dcdb5c3121f827 Xiubo Li    2021-07-05  2304             for (i = 0; i < max; 
i++) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2305                     s = sessions[i];
dcdb5c3121f827 Xiubo Li    2021-07-05  2306                     if (s) {
dcdb5c3121f827 Xiubo Li    2021-07-05  2307                             
send_flush_mdlog(s);
dcdb5c3121f827 Xiubo Li    2021-07-05  2308                             
ceph_put_mds_session(s);
dcdb5c3121f827 Xiubo Li    2021-07-05  2309                     }
dcdb5c3121f827 Xiubo Li    2021-07-05  2310             }
dcdb5c3121f827 Xiubo Li    2021-07-05  2311             kfree(sessions);
dcdb5c3121f827 Xiubo Li    2021-07-05  2312     }
dcdb5c3121f827 Xiubo Li    2021-07-05  2313  
4945a084799e24 Jeff Layton 2016-11-16  2314     dout("unsafe_request_wait %p 
wait on tid %llu %llu\n",
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2315          inode, req1 ? req1->r_tid 
: 0ULL, req2 ? req2->r_tid : 0ULL);
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2316     if (req1) {
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2317             ret = 
!wait_for_completion_timeout(&req1->r_safe_completion,
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2318                                     
ceph_timeout_jiffies(req1->r_timeout));
da819c8150c5b6 Yan, Zheng  2015-05-27  2319             if (ret)
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2320                     err = -EIO;
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2321             
ceph_mdsc_put_request(req1);
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2322     }
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2323     if (req2) {
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2324             ret = 
!wait_for_completion_timeout(&req2->r_safe_completion,
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2325                                     
ceph_timeout_jiffies(req2->r_timeout));
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2326             if (ret)
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2327                     err = -EIO;
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2328             
ceph_mdsc_put_request(req2);
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2329     }
dcdb5c3121f827 Xiubo Li    2021-07-05  2330  out:
68cd5b4b7612c2 Yan, Zheng  2015-10-27  2331     return err;
da819c8150c5b6 Yan, Zheng  2015-05-27  2332  }
da819c8150c5b6 Yan, Zheng  2015-05-27  2333  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

Attachment: .config.gz
Description: application/gzip

_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to